kivy入门之布局(三)

创建锚点布局

 1 from kivy.app import App
 2 from kivy.core.text import LabelBase
 3 from kivy.uix.anchorlayout import AnchorLayout
 4 
 5 LabelBase.register("Roboto", "msyhl.ttc")
 6 
 7 
 8 class Test8layout(AnchorLayout):
 9     """锚点布局"""
10     ...
11 
12 
13 class Test8App(App):
14     def build(self):
15         return Test8layout()
16 
17 
18 if __name__ == '__main__':
19     Test8App().run()

kv语言:

 1 <Test8layout>:
 2     padding:20
 3     AnchorLayout:
 4         anchor_x:'left'
 5         anchor_y:'top'
 6         Button:
 7             text:'只有永不遏止的奋斗'
 8             size_hint: .3, .2
 9     AnchorLayout:
10         anchor_x:'right'
11         anchor_y:'bottom'
12         Button:
13             text:'才能使青春之花'
14             size_hint:.3,.2

运行界面显示:

 

posted on 2022-09-26 11:35  默玖  阅读(84)  评论(0编辑  收藏  举报

导航