from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
kv = """
ScreenManager:
id: manager
HomeScreen:
name : 'home_screen'
MDLabel:
text: 'home_screen'
halign: 'center'
MDRectangleFlatButton:
text: 'go to input_screen'
pos_hint: {'center_x': .5, 'center_y': .3}
on_press: app.change_screen('input_screen')
InputScreen:
name : 'input_screen'
MDLabel:
text: 'input_screen'
halign: 'center'
MDRectangleFlatButton:
text: 'go to home_screen'
pos_hint: {'center_x': .5, 'center_y': .3}
on_press: app.change_screen('home_screen')
"""
class HomeScreen(Screen):
pass
class InputScreen(Screen):
pass
class TestApp(MDApp):
def build(self):
self.theme_cls.primary_palette = "Teal"
return Builder.load_string(kv)
def change_screen(self, screen_name):
self.root.ids.manager.current = screen_name
if __name__ == "__main__":
TestApp().run()
The issue is that the screenmanager is your rootwidget, so you don’t need to go into the ids to address the screenlmanager.
When you have these kinds of issues you can print out the elements of the pointer you are using…
In app if you print(self.root) you will see it is the ScreenManager. Therefore access current as:
def change_screen(self, screen_name):
self.root.current = screen_name
Alternatively if you put the ScreenManager in a BoxLayout, then the ScreenManager is no longer the root widget and your original code should work.
--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/0c37062c-ff31-4b08-a9bf-f8f16b658011%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.