【Kivy】RecycleView を表示する

  • main.py
from kivy.app import App

class MainApp(App):
    pass

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

RecycleView:
    data: [{'text': 'Item 1'}, {'text': 'Item 2'}, {'text': 'Item 3'}]
    viewclass: 'Label'
    RecycleBoxLayout:
        default_size: None, dp(56)
        default_size_hint: 1, None
        size_hint_y: None
        height: self.minimum_height
        orientation: 'vertical'

youtu.be

【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:

youtu.be

【Kivy】ScrollView を表示する

  • main.py
from kivy.app import App

class MainApp(App):
    pass

if __name__ == '__main__':
    MainApp().run()
  • main.kv
#:kivy 1.0
ScrollView:
    do_scroll_x: False
    do_scroll_y: True

    Label:
        size_hint_y: None
        height: self.texture_size[1]
        padding: 10, 10
        text:
            'really some amazing text\n' * 100

youtu.be

【Kivy】ModalView を表示する

  • main.py
from kivy.app import App

class MainApp(App):
    pass

if __name__ == '__main__':
    MainApp().run()
  • main.kv
#:kivy 1.0
#:import Factory kivy.factory.Factory
<MyModalView@ModalView>:
    auto_dismiss: False
    size_hint: .5, .5
    pos_hint: {'center_x': .5, 'center_y': .5}
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'Hello World'
        Button:
            size_hint_y: None
            height: 80
            text: 'Close'
            on_release: root.dismiss()

Button:
    text: 'Open Popup'
    on_release: Factory.MyModalView().open()

youtu.be