I have an app but how do i change screen not through the kv, but through the python function, There is my python code and i get an error name 'root' is not defined. Tried to do the same thing but with self and it said that MainApp has no attribute screen_manager, so how do i access it?
class Main(MDBoxLayout):
pass
class LoginScreen(Screen):
pass
class MainApp(MDApp):
def build(self):
return Builder.load_file("Main.kv")
def on_start(self):
if is_logged():
self.screen_manager.current="main_screen"
else:
self.screen_manager.current="login_screen"
def is_logged():
return False
MainApp().run()
also here is my kv code
<LoginScreen>:
id: login_screen
text: "Login"
icon: "login"
MDBoxLayout:
orientation: "vertical"
MDLabel:
text:"Welcome to Plaim"
font_style:"H4"
text_color:"0,0,0,1"
MDTextField:
hint_text:"login"
id: username
hint_text: "Username"
required: True
helper_text_mode: "on_error"
MDTextField:
hint_text:"password"
id: password
password: True
hint_text: "Password"
required: True
helper_text_mode: "on_error"
MDRaisedButton:
text: "Sign In"
on_release:
app.change_screen("main_screen")
<Main>:
orientation: "vertical"
id: main
ScreenManager:
LoginScreen:
name: "login_screen"
id: login_screen
MainScreen:
name: "main_screen"
id: main_screen
question from:https://stackoverflow.com/questions/66068943/how-do-i-change-screen-through-the-function