はじラボ

プログラミングで何ができるか、初学者が色々試してみるブログ

【第1回】Python の GUI ライブラリ「Kivy」を使ってみる

ネットで調べながら、タイマーを意識した画面レイアウトにしました。
これから細かい設定を試していこうと思います。

from kivy.app import App

# our imports
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button

# create the outer layout
main_layout = AnchorLayout(anchor_x="center", anchor_y="bottom")

# create the inner layout
inner_layout = BoxLayout(size_hint=(1, .2))

# add the bottons to the BoxLayout
btns = ["Start", "Stop", "Reset"]
for btn in btns:
inner_layout.add_widget(Button(text=btn))

# add the inner layout to the outer layout
main_layout.add_widget(inner_layout)

class TestApp(App):
def build(self):
return main_layout

if __name__ == '__main__':
TestApp().run()

実行結果