[Kivy] Initialize widget value from Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Kivy] Initialize widget value from Python (/thread-10599.html) |
Initialize widget value from Python - j.crater - May-27-2018 I can't for the life of me get my code to initialize a widget (in a kv file) from Python code on program startup. Simplified Python code is here: inital_text = "init text" class MainApp(App): def initialize_widgets(self): self.root.ids.my_label.text = initial_text if __name__ == '__main__': MainApp().run() MainApp.initialize_widgets(App)And kv file: Label: id: my_label text: "default text"When I run the program, the label says "default text". When quitting it, I get the error: I have tried various workarounds, many quite desperate ones, with no success. Help is much appreciated.
RE: Initialize widget value from Python - Larz60+ - May-27-2018 perhaps a dumb question, but do you import APP? from kivy.app import App RE: Initialize widget value from Python - j.crater - May-27-2018 I do, I get the window drawn. I found App on_start method to be of some use. Looks like its purpose is for profiling, but it can be used for initializing values. |