【问题标题】:How to increase the height of a cell in Kivy如何在 Kivy 中增加单元格的高度
【发布时间】:2021-11-20 03:52:58
【问题描述】:

我正在尝试为我的 AI 制作一个 GUI,并正在尝试为它制作一个模板。但是我的“TESTER-MAN”按钮没有填满它下面的空白,留下一个。差距以及会缩小我的形象的因素。在尝试增加单元格的高度以填充空白区域时,我想获得一些帮助。

python3:

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout

class BoxLayoutE(BoxLayout):
    pass

class guiApp(App):
    pass


guiApp().run()

.kv

 BoxLayoutE:



<BoxLayoutE>:

orientation: "vertical"
Button:
    text: "TESTER-MAN"

BoxLayout:
    orientation: "horizontal"
    Button:
        text: "1"
        color: 0, 0, 1, 1
        size_hint: .5, None
    Button:
        text: "2"
        color: 0, 0, 1, 1
        size_hint: .5, None
    Button:
        text: "3"
        color: 0, 0, 1, 1
        size_hint: .5, None
Button:
    text: "A"
    color: 0, 0, 1, 1
Button:
    text: "B"
    color: 0, 0, 1, 1
Button:
    text: "C"
    color: 0, 0, 1, 1

GUI 的图片以及 的位置

【问题讨论】:

    标签: python python-3.x kivy


    【解决方案1】:

    问题在于,在您的水平BoxLayout 中,您为每个Buttons 分配了size_hint(.5, None),因此那些Buttons 不会垂直填充BoxLayout。尝试将kv 的那部分更改为:

    BoxLayout:
        orientation: "horizontal"
        Button:
            text: "1"
            color: 0, 0, 1, 1
            size_hint: .5, 1
        Button:
            text: "2"
            color: 0, 0, 1, 1
            size_hint: .5, 1
        Button:
            text: "3"
            color: 0, 0, 1, 1
            size_hint: .5, 1
    

    注意size_hints 现在是.5, 1,所以Buttons 垂直填充空间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 1970-01-01
      • 2015-03-20
      • 2017-04-26
      相关资源
      最近更新 更多