【Kivy】ScreenManager を利用する

  • main.py
from kivy.app import App

class MainApp(App):
    pass

if __name__ == '__main__':
    MainApp().run()
  • main.kv
#:kivy 1.0

<Screen_1@Screen>:
    name: 'Screen 1'
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'Display 1'
        Button:
            size_hint_y: None
            height: 120
            text: 'To Screen 2'
            on_press: root.manager.current = 'Screen 2'
<Screen_2@Screen>:
    name: 'Screen 2'
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'Display 2'
        Button:
            size_hint_y: None
            height: 120
            text: 'To Screen 3'
            on_press: root.manager.current = 'Screen 3'
<Screen_3@Screen>:
    name: 'Screen 3'
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'Display 3'
        Button:
            size_hint_y: None
            height: 120
            text: 'To Screen 1'
            on_press: root.manager.current = 'Screen 1'

ScreenManager:
    Screen_1:
    Screen_2:
    Screen_3: