My app gets data from a database and and is stored into variables in Python. The code below is a simplified version where you have two screens. The first screen has two buttons and the second screen has a label and a back button. The text of the label on the second screen will change depending on what button is pressed.
When run, the label is set to the value of the StringProperty, which is "Test". When one of the buttons are clicked the ChangeScreen function is run and works out the correct new label. The LabelUpdater function on the second is run which should change the string property but doesn't. How do I fix this issue? Thanks <3
Python:Kivy:import kivy from kivy.app import App from kivy.uix.screenmanager import ScreenManager, Screen from kivy.properties import StringProperty class DemoScreen1(Screen): def ChangeScreen(self, button_text): if button_text == "Button 1": new_label = "This is the new label when button 1 is pressed" DemoScreen2.LabelUpdater(new_label) else: new_label2 = "This is the new label when button 2 is pressed" DemoScreen2.LabelUpdater(new_label2) self.parent.current = "demoscreen2" class DemoScreen2(Screen): screen2_label = StringProperty("Test") def LabelUpdater(NEW_LABEL): screen2_label = StringProperty(NEW_LABEL) class AppScreenManager(ScreenManager): pass class Tester(App): pass if __name__ == '__main__': Tester().run()
AppScreenManager: DemoScreen1: DemoScreen2: <DemoScreen1>: name: "demoscreen1" orientation: "vertical" GridLayout: rows: 2 Button: id: Button1 text: "Button 1" on_release: root.ChangeScreen(Button1.text) Button: id: Button2 text: "Button 2" on_release: root.ChangeScreen(Button2.text) <DemoScreen2>: name: "demoscreen2" orientation: "vertical" GridLayout: rows:2 Label: text: root.screen2_label Button: text:"Back" on_release: app.root.current = "demoscreen1"
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.