【问题标题】:Kivy Change Z-indexKivy 改变 Z 指数
【发布时间】:2018-08-14 12:18:46
【问题描述】:

我仍然掌握 kivy 和 python 的窍门,所以请耐心等待。我有两个布局,我的 Graph 布局覆盖了我的 TopBar 布局的属性。有没有办法解决这个问题?

这是我的 .kv 文件:

Root:
    orientation: "vertical"

    TopBar:
        size_hint: 1,0.08
        size_hint_max_y: 100
        pos_hint: {"top":1}

        TextInput:
            text: "Search"
            right: True
            size_hint_max_x: 200
        Button:
            text: str(self.state)
    Graph:
        size_hint_max_y: 100
        Button:
            text: "test"

这是python文件:

class Root(BoxLayout):
    def __init__(self, **kwargs):
        super(Root, self).__init__(**kwargs)


class TopBar(BoxLayout):
    pass

class Graph(FloatLayout):
    pass

class Gui(App):
    def build(self):
       return Root()

Gui().run()

谢谢!

【问题讨论】:

    标签: python python-3.x kivy kivy-language


    【解决方案1】:

    kv文件

    size_hint_max_y: 100Graph: 下移动到Button: 下。

    在 sn-p 中,添加了颜色以说明 Graph 的画布。

    片段

    Graph:
        canvas.before:
            Color:
                rgba: 0, 0, 1, 0.5    # 50% blue
            Rectangle:
                pos: self.pos
                size: self.size
    
        Button:
            size_hint_max_y: 100
            text: "test"
    

    输出

    【讨论】:

    • 谢谢 之前没有意识到,但是有没有办法调整实际布局的大小?
    • 调整Graph布局,例如:使用size_hint: 1, Nonesize_hint_y: 0.5
    猜你喜欢
    • 2018-11-26
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    相关资源
    最近更新 更多