代码:
import kivy
kivy.require("1.9.1")
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
class BoxLayoutApp(App):
def build(self):
HB = BoxLayout(orientation='horizontal')
HB.add_widget(Label(text="One", font_size='80sp',color = [0.5, 0.5, 1, 1]))
HB.add_widget(Label(text="Two", font_size='90sp',color = [0.5, 1, 0.5, 1]))
VB = BoxLayout(orientation='vertical')
VB.add_widget(Label(text="Three",font_size='80sp',color = [1, 0.5, 0.5, 1]))
VB.add_widget(Label(text="Four" ,font_size='70sp',color = [1, 0.5, 1, 0.5]))
superBox = BoxLayout(orientation='vertical')
superBox.add_widget(HB)
superBox.add_widget(VB)
return superBox
root = BoxLayoutApp()
root.run()
运行结果:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/f9a43e748274e2501e62bba88fab693c.png#pic_center)
布局 | 说明 |
---|
floatlayout | 浮动布局 |
boxlayout | 盒式布局 |
gridlayout | 网格布局 |
stacklayout | 栈式布局 |
relativelayout | 相对布局 |
anchorlayout | 锚式布局 |