如何在Kivy中设置小部件深度?

时间:2014-04-01 21:48:22

标签: user-interface kivy

我正在设计一个基于Kivy的简单应用,它在Scatter小部件中有一个图像,在屏幕上的固定位置有两个按钮。

depthproblem.kv:

FloatLayout:
    Scatter:
        Image:
            source: "img.png"
    Button:
        text: "Alpha"
        pos_hint: {"x":0.00, "y":0}
        size_hint: 0.20, 0.15
    Button:
        text: "Beta"
        pos_hint: {"x":0.20, "y":0}
        size_hint: 0.20, 0.15

depthproblem.py:

from kivy.app import App

class DepthProblemApp(App):
    pass

DepthProblemApp().run()

程序从图像顶部的按钮开始,这就是我想要的。这是因为按钮是在分散后声明的。

但是当我触摸图像时,它会将图像层提升到按钮上方。我不明白为什么会发生这种情况,也无法找到有关如何控制此行为的任何文档(搜索的z-index,顺序,图层,深度等)。

如何指定始终在散点图像上绘制的按钮?


Good Bad

1 个答案:

答案 0 :(得分:3)

通过将auto_bring_to_front设置为False,可以解决前方散点图像的问题。默认为True,这就是您获得该行为的原因。

通常,z-index(深度顺序)可以通过添加小部件的顺序来控制。添加的最后一个,显示在顶部,我相信。请参阅add_widget的索引。