Kivy screenmanager current screen not switching (at least not visually). Using kivymd
Solution 1:
You are creating a GUI using the lines:
scrMng = ScreenManager()
scrMng.add_widget(Screen1(name = "screen1"))
scrMng.add_widget(Screen2(name = "screen2"))
But the scrMng
created above is never used, so those lines can be eliminated. And the reference to scrMng
in the python code will do nothing, since scrMng
is not actually part of your app.
Your GUI is actually created by the line:
return Builder.load_file("main.kv")
Then the Screen
classes can become:
class Screen1(Screen):
def SwitchScreen(self):
self.manager.current = "screen2"
class Screen2(Screen):
def SwitchScreen(self):
self.manager.current = "screen1"
Note that self.manager
in a Screen
class is always a reference to its ScreenManager
.