【Kivy】FloatLayout を利用し、画面サイズに応じて配置する

  • main.py
from kivy.app import App

class MainApp(App):
    pass

if __name__ == '__main__':
    MainApp().run()
  • main.kv
#:kivy 1.0
FloatLayout:
    Button:
        text: 'button 1'
        size_hint: .4, .2
        pos_hint: {'x':.2, 'y':.3}
    Button:
        text: 'button 2'
        size_hint: .4, .2
        pos_hint: {'x':.5, 'y':.2}
    Button:
        text: 'button 3'
        size_hint: .4, .3
        pos_hint: {'x':.3, 'y':.6}
    Button:
        text: 'button 4'
        size_hint: .4, .2
        pos_hint: {'x':.5, 'y':.5}

youtu.be

【Kivy】BoxLayout を利用し、横に並べる

  • main.py
from kivy.app import App

class MainApp(App):
    pass

if __name__ == '__main__':
    MainApp().run()
  • main.kv
#:kivy 1.0
BoxLayout:
    orientation: 'horizontal'
    Button:
        text: 'button 1'
    Button:
        text: 'button 2'
    Button:
        text: 'button 3'
    Button:
        text: 'button 4'

youtu.be

【Kivy】ActionBar を表示する

  • main.py
from kivy.app import App

class MainApp(App):
    pass

if __name__ == '__main__':
    MainApp().run()
  • main.kv
#:kivy 1.0
ActionBar:
    ActionView:
        ActionPrevious:
            title: 'Previous'
            with_previous: False
        ActionButton:
            text: 'button'

youtu.be

【Kivy】Splitter を利用する

  • main.py
from kivy.app import App

class MainApp(App):
    pass

if __name__ == '__main__':
    MainApp().run()
  • main.kv
#:kivy 1.0
BoxLayout:
    Splitter:
        sizable_from: 'right'
        strip_size: '10pt'
        Label:
            text: 'item 1'
    Label:
        text: 'item 2'

youtu.be

【Kivy】Canvas で任意の描画を行う

  • main.py
from kivy.app import App

class MainApp(App):
    pass

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

<ColorBox@Widget>:
    color: [1, 1, 1]
    canvas:
        Color:
            rgb: root.color
        Rectangle:
            size: self.size
            pos: self.pos
            
Widget:
    ColorBox:
        size_hint: None, None
        size: 100, 100
        pos_hint: None, None
        pos: 0, 0
        color: [1, 1, 1]
    ColorBox:
        size_hint: None, None
        size: 100, 100
        pos_hint: None, None
        pos: 50, 50
        color: [1, 0, 0]

youtu.be