答案 0 :(得分:1)
您应该只在GridLayout
内嵌入BoxLayout
并使用size_hint
来选择小部件应占用多少空间。例如size_hint: 1, 0.25
结果,小部件水平占用所有可用空间,垂直占用可用空间的1/4。结果:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty
from kivy.lang import Builder
Builder.load_string('''
<MyWidget>:
orientation: 'vertical'
Label:
size_hint: 1, 0.25
text: 'Label1'
GridLayout:
size_hint: 1, 0.25
cols: 2
Button
text: 'Button1'
Button
text: 'Button2'
Button
text: 'Button3'
Button
text: 'Button4'
Label:
size_hint: 1, 0.5
text: 'Label2'
''')
class MyWidget(BoxLayout):
pass
class MyApp(App):
def build(self):
return MyWidget()
if __name__ == '__main__':
MyApp().run()