【Kivy】任意の描画を行う

  • 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]