Hello all,
so, I have the following files:
main.py
increment() and decrement() functions alter the number variable, which in turn effects what text label on GUI shows.
But I would like to be able to reset the parameters to default. I thought this could simply be done by reassigning a Data() class to gui_data variable in application class. This would reset the variables to defaults (imagining there will be many), while the .kv keeps the reference to the same gui_data object. However, since reassigning (reset_parameters())the text label doesn't return to the number's default value, nor responds to button presses.
I also tried with class' init method (in comments), but outcome was same.
What am I missing here, why does label/text in .kv (seem to) lose reference to gui_data object?
Thanks,
JC
so, I have the following files:
main.py
from kivy.app import App import parameters class MainApp(App): gui_data = parameters.Data() def increment(self): self.gui_data.number = str(int(self.gui_data.number) + 1) def decrement(self): self.gui_data.number = str(int(self.gui_data.number) - 1) def reset_parameters(self): self.gui_data = parameters.Data() if __name__ == '__main__': MainApp().run()parameters.py
from kivy.properties import StringProperty from kivy.event import EventDispatcher class Data(EventDispatcher): number = StringProperty("0") # number = StringProperty() # def __init__(self): # self.number = "0"main.kv
BoxLayout: orientation: "vertical" Label: text: app.gui_data.number Button: text: "Increment" on_press: app.increment() Button: text: "Decrement" on_press: app.decrement() Button: text: "Reset parameters" on_press: app.reset_parameters()I know there are shortcuts to implement what the program above is doing, but I am trying to make a skeleton for a larger piece of code.
increment() and decrement() functions alter the number variable, which in turn effects what text label on GUI shows.
But I would like to be able to reset the parameters to default. I thought this could simply be done by reassigning a Data() class to gui_data variable in application class. This would reset the variables to defaults (imagining there will be many), while the .kv keeps the reference to the same gui_data object. However, since reassigning (reset_parameters())the text label doesn't return to the number's default value, nor responds to button presses.
I also tried with class' init method (in comments), but outcome was same.
What am I missing here, why does label/text in .kv (seem to) lose reference to gui_data object?
Thanks,
JC