【问题标题】:How to remove the space between two BoxLayouts in Kivy?如何删除 Kivy 中两个 BoxLayouts 之间的空间?
【发布时间】:2022-01-02 08:03:22
【问题描述】:

我声明我已经阅读了其他用户对这个问题的回答,但他们都没有帮助我。我正在尝试使用 kivy GUI 界面在 python 中编写一个计算器,他的问题是我无法删除此处所附照片中以红色突出显示的空间。我已经尝试过: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
       

【问题讨论】:

    标签: python user-interface interface kivy calculator


    【解决方案1】:

    您的问题是您正在设置按钮的 size_hint 相对于其父 BoxLayout。所以实际上你的 BoxLayout 占用了 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的大小

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-10
      • 1970-01-01
      • 2019-12-08
      • 2020-12-01
      • 2021-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多