gridlayout在kv中的引用

from kivy.app import App
from kivy.uix.gridlayout import GridLayout


class GridLayoutWidget(GridLayout):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)


class GridLayoutApp(App):
    def build(self):
        return GridLayoutWidget()


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

==============kv段================

<GridLayoutWidget>:
padding:20
spacing:20
cols:3

  # 打开强制默认列数宽度
  # 将所没有默认宽度的部件设为200
  col_force_default:True
  col_default_200

  # 打开强制默认行高
  # 设置默认行高
  row_force_default:True
  row_default_height:40
  
  # 全局列宽{列号:宽度}
  minimum:{0:130,1:140}
  # 全局行高{行号:高度}
  rows_minimum:{0:60}
  # 优先级 width>cols_minimum>col_default_width

  Button:
text:'bt1'
size_hint_x:None
     # 此处设为固定宽度
'100px'
    

Button:
text:'bt2'
Button
text:'bt3'
Button
text:'bt4'
原文地址:https://www.cnblogs.com/vip136510786/p/14604803.html