Search code examples
pythonpython-3.xkivykivy-language

Kivy Change Z-index


I'm still getting the hang of both kivy and python so bear with me. I have two layouts, my Graph layout is overriding the properties of my TopBar layout. Is there any way to fix this?

Here is my .kv file:

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"

Here's the python file:

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

Thanks!


Solution

  • kv file

    Move size_hint_max_y: 100 from under Graph: to under Button:.

    In the snippet, color was added to illustrates the Graph's canvas.

    Snippet

    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"
    

    Output

    Img01