May-27-2018, 11:39 AM
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:
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:
Error:line 5, in initialize_widgets
self.root.ids.my_label.text = initial_text
AttributeError: type object 'App' has no attribute 'root'
I have tried various workarounds, many quite desperate ones, with no success. Help is much appreciated.