如何删除 Kivy 中两个 BoxLayouts 之间的 space?

How to remove the space between two BoxLayouts in Kivy?

我声明我已经阅读了其他用户对这个问题的回答,但其中 none 帮助了我。 我正在尝试编写一个计算器python 使用 kivy GUI 界面,他的问题是我无法删除 space 突出显示的 红色附上的照片在这里。我已经尝试过:size_hint: None,Nonesize:root.size[0], "5dp" 来缩放 BoxLayouts 但它不起作用

         [1]: https://i.stack.imgur.com/y1ZwF.png


  BoxLayoutExample:
<BoxLayoutExample>:
    orientation: "vertical"
    Label:
        text: "0"
        font_size: "30dp"
    BoxLayout:
        orientation: "horizontal"
        Button:
            text: "7"
            size_hint: .1, .3
        Button:
            text: "4"
            size_hint: .1, .3
        Button:
            text: "1"
            size_hint: .1, .3

    BoxLayout:
        orientation: "horizontal"
        Button:
            text: ","
            size_hint: .1, .3
        Button:
            text: "0"
            size_hint: .1, .3
        Button:
            text: "="
            size_hint: .1, .3
       

您的问题是您正在设置按钮的 size_hint 相对于其父级 BoxLayout。因此,实际上您的 BoxLayout 占用了可用 space 的 1/3(因为 BoxLayoutExample.

中有三个小部件

修复方法如下:

<BoxLayoutExample>:
    orientation: "vertical"

    Label:
        text: "0"
        font_size: "30dp"
        size_hint: 1, .8

    BoxLayout:
        orientation: "horizontal"
        size_hint: 1, .1
        Button:
            text: "7"
        Button:
            text: "4"
        Button:
            text: "1"

    BoxLayout:
        orientation: "horizontal"
        size_hint: 1, .1
        Button:
            text: ","
        Button:
            text: "0"
        Button:
            text: "="

相应地调整 LabelBoxLayout 的大小