Search code examples
pythonkivy

Kivy BoxLayout align widgets to the top border


I'm using the following Kivy code to create BoxLayout with buttons:

BoxLayout:
    orientation: "vertical"
    width: 200
    size_hint_x: None

    Button:
        size_hint_y: None
        height: 30
        text: 'btn1'

    Button:
        size_hint_y: None
        height: 30
        text: 'btn2'

    Button:
        size_hint_y: None
        height: 30
        text: 'btn3'

But buttons stick to the bottom edge, how can i push them towards the top edge of the layout?

enter image description here


Solution

  • You can also put an empty Widget at the end to take up the space.

    BoxLayout:
        orientation: "vertical"
        width: 200
        size_hint_x: None
    
        Button:
            size_hint_y: None
            height: 30
            text: 'btn1'
    
        Button:
            size_hint_y: None
            height: 30
            text: 'btn2'
    
        Button:
            size_hint_y: None
            height: 30
            text: 'btn3'
    
        Widget: