After I collect the user input in kivy, I want to use it to update all my screens(arranged in classes). The issue is that when I collect the username from the first screen, I am finding it difficult to use the username to make updates on the other screens. For example, the second screen contains a label that says hello, username. However, after switching to the second screen, it retains its default value. What I have tried:
- I tried creating a function in the second window and using the return value(which contains the username) as the text for the label. To do so I had to initialize it at first. Unfortunately, it seems that despite I call the function when I switch to the next screen(by pressing a button), the label has already been initialized and would not change its value.
I tried looking for an on_load function in kivy to update it when the window loads, but I couldn't find any.
Code
class MainWindow (Screen):
'''This is the mainwindow class where I collect the user input'''
password = ObjectProperty(None)
username = ObjectProperty(None)
active_user = ObjectProperty(None)
def check(self):
if self.password.text in Student.LIST_OF_STUDENTS.keys():
self.active_user = Student.LIST_OF_STUDENTS[self.password.text]
#After collecting user input I tried setting the username to SeconWindow's attribute (user)
#So when I click the submit button and it verifies, it would change the username in the second window
SecondWindow.user = self.active_user.club
return True
class SecondWindow (Screen):
'''THis is the Second window and its property user'''
user = Student.LIST_OF_STUDENTS['123'].club
This is the Kv file, linking the second window
<SecondWindow>
name: 'second'
FloatLayout:
Label
text: root.user
pos_hint: {'y':0.9, 'x':0.1}
text_size: self.size
font_size: 30
However, when It switches to the second window, the label just retains its original user's name rather than switching to the 'new' one. Even though I changed it with the submit button in the first class.