有没有办法在 kivy BoxLayouts 周围放置边框?

时间:2021-02-08 10:52:21

标签: user-interface kivy

我正在为我正在创建的应用程序设计一个主菜单,但我似乎无法弄清楚如何在 kivy 中为 boxlayout 设置边框,有没有办法做到这一点?如果是这样,有人可以帮忙。我曾尝试使用 canvas.before 并为矩形设置边界,但这不起作用。

<MainMenuWindow>:
    id: Main_Menu_window  ## setting the id to Login_window

    BoxLayout: ## whole screen
        orientation: 'horizontal'

        BoxLayout: ## left hand side 1/3
            canvas.before:
                Color:
                    rgba: 0, 0, 0, 1
                Line:
                    width:
                    rectangle: self.x, self.y, self.width, self.height

            orientation: 'vertical' ## setting orientation of the screen to vertical
            size_hint_x: 1/3 ## setting size of box to 1/3 of the screen
            canvas.before:
                Color: ## just for debugging reasons
                    rgba: (255/255,255/255,255/255, 1)  ## setting colour
                Rectangle:
                    size: self.size  ## setting size to the size of the box layout
                    pos: self.pos  ## setting position to the position of the box layout

1 个答案:

答案 0 :(得分:0)

A BoxLayout 试图通过为每个孩子分配一个共享空间来使用其所有可用空间。由于您的内部 BoxLayout 是外部 BoxLayout 的唯一子节点,因此它将被分配外部 BoxLayout 的整个空间。因此,您可以通过调整外部 BoxLayout 的大小,或通过显式设置内部 BoxLayoutsize(使用 { {1}})。

因此,这是一种将内部 BoxLayout 设置为屏幕宽度三分之一的方法:

size_hint: None, None
相关问题