gird.kv
<GridLayoutWidget>:
padding: 20 #布局和子集填充间距
spacing: 20 #子集和子集填充间距
cols: 3 #行数 rows列数
col_force_default: True#强制默认列宽
col_default_width: 120#设置默认列宽
row_force_default: True
row_default_height: 40
cols_minimum: {0:130, 1:140}#设置列宽,第一列130,第二列140
canvas:
Color:
rgba: [1, 1, 1, 1]
Rectangle:
size: self.size
pos: self.pos
Button:
text: 'First'
size_hint_x: None
width: '100px'
Button:
text: 'Second'
Button:
text: 'Third'
Button:
text: 'Fourth'
main.py
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
class GridLayoutWidget(GridLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
class GridApp(App):
def build(self):
return GridLayoutWidget()
if __name__ == "__main__":
GridApp().run()
kivy学习完全解析 006 GridLayout 网格布局
最新推荐文章于 2023-12-31 20:41:07 发布