Python Forum
[Kivy] GUI properties defined (and changed) by variables in .py file
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Kivy] GUI properties defined (and changed) by variables in .py file
#1
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:

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 str
main.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
Reply


Messages In This Thread
GUI properties defined (and changed) by variables in .py file - by j.crater - Aug-07-2018, 07:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Menus and icons changed after upgrade blackclover 0 1,959 May-11-2018, 08:14 PM
Last Post: blackclover
  PyGtk3, How to Create “title-changed” signal for Gtk.Window Widget? harun2525 2 6,171 May-01-2017, 07:59 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020