I'm designing a simple Kivy-based app that has an image in a Scatter widget and two buttons at a fixed position on the screen.

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()

The program starts with the buttons on top of the image, which is what I intend. This is because the buttons are declared after the scatter.

But when I touch the image, it lifts the image layer above the buttons. I don't understand why this happens, and couldn't find any documentation about how to control this behavior (searched z-index, order, layer, depth, etc.).

How can I specify the buttons to always be painted on top of the scatter/image?


Good Bad

有帮助吗?

解决方案

Your problem with the scatter image coming to the front can be fixed by setting auto_bring_to_front to False. It defaults to True which is why you're getting that behavior.

Normally, the z-index (depth order) can be controlled by the order in which the widgets are added. The last one added, is displayed at the top I believe. See index of add_widget.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top