I'm using kivy kivyMD and pyrebase, to do the login game or return from Firebase in a "user" variable, I want to use this variable to reconnect at any time inside the Login class.
Or problem is when I do or login correctly it directs me to another class and then I can't recover this value anymore.
Below is an example that is minimalist to guide me that can help me:
On line 117 I have a variable with any value. I would like to use this variable in a class that I HAVE to create in the fabric "scr 1" in line 44 (Note that I still do not create a class because I am giving a minimalist example)
I would like to obtain this value through the python code and not in the kv file.
CodePudding user response:
You may achieve that as follows :
- Create an
ObjectProperty
inMainScreen
to refer the target label as,
class MainScreen(Screen):
user_name = ObjectProperty()
- Then in
kvlang
ofMainScreen
,
<MainScreen>:
user_name: user_name
.
.
.
Screen:
name: "scr 1"
MDLabel:
id: user_name
.
.
.
- Now in method
login
of classTelaLogin
,
def login(self):
user = 'Helo im user'
manager = self.manager
manager.current = 'main'
manager.current_screen.user_name.text = user
# You can also use method 'get_screen'.