アンカーレイアウト

2015/10/24

公式サンプルそのまま。

# -*- coding: utf-8 -*-

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.anchorlayout import AnchorLayout

class MyApp(App):

    def build(self):
        anchor = AnchorLayout(anchor_x='center',anchor_y='bottom')
        btn = Button( text='Hello World',
                      size=(300,100),
                      size_hint=(None,None) )
        anchor.add_widget(btn)        
        return anchor

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

Anchor Layout
http://kivy.org/docs/api-kivy.uix.anchorlayout.html


Kvファイルでやるとこんな感じ

# -*- coding: utf-8 -*-

from kivy.app import App
from kivy.lang import Builder

kv = '''
AnchorLayout:
    anchor_x: 'center'
    anchor_y: 'center'
    Button:
        text: 'Hello World'
        size: 300,100
        size_hint: None, None
'''

class MyApp(App):
    def build(self):
        return Builder.load_string(kv)

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