Aug-07-2018, 07:15 AM
Hello all,
I am trying to make a basis for a MVC-sytle program, where GUI properties (in .kv file) would be stored and accessed from a separate .py file. I tried a couple of things, but as I am not yet too familiar with Kivy, I had no success so far.
Value of label_text does change with pressing buttons (increment or decrement), but label text remains same ("0"), though I would like it to change dynamically.
The code in files is:
main.py:
JC
I am trying to make a basis for a MVC-sytle program, where GUI properties (in .kv file) would be stored and accessed from a separate .py file. I tried a couple of things, but as I am not yet too familiar with Kivy, I had no success so far.
Value of label_text does change with pressing buttons (increment or decrement), but label text remains same ("0"), though I would like it to change dynamically.
The code in files is:
main.py:
from kivy.app import App import values class MainApp(App): def increment(self): values.label_text = str(int(values.label_text) + 1) def decrement(self): values.label_text = str(int(values.label_text) - 1) if __name__ == '__main__': MainApp().run()values.py:
from kivy.properties import StringProperty label_text = "0" # label_text = StringProperty("0") # gives: ValueError: Label.text accept only strmain.kv:
#:import val values BoxLayout: orientation: "vertical" Label: text: val.label_text Button: text: "increment" on_press: app.increment() Button: text: "decrement" on_press: app.decrement()Any tips are most appreciated, thanks.
JC