shadowjig
shadowjig

Reputation: 43

Kivy BoxLayout - move widgets to the top

I have all the widgets sized and positioned relative to one another. If I add a "Label:" to the bottom of the kv code it will move everything up to the top. But that can't be the "right" way to do it. What am I missing?

import kivy
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder

Builder.load_string('''
<Controller>:
    BoxLayout:
        orientation: 'vertical'
        padding: 20
        spacing: 20
        TextInput:
            hint_text: 'Feed Name'
            multiline: False
            size_hint: (0.75, None)
            height: 30
            pos_hint: {'center_x': 0.5}
        TextInput:
            hint_text: 'Feed URL'
            multiline: True
            size_hint: (0.75, None)
            height: 68
            pos_hint: {'center_x': 0.5}
        Button:
            text: 'Add Feed'
            padding: (10, 10)
            height: 30
            size_hint: (None, None)
            pos_hint: {'center_x': 0.5}
''')

class Controller(BoxLayout):
    pass

class PodcastApp(App):
      def build(self):
          return Controller(info='Hello world')

if __name__ == '__main__':
    PodcastApp().run()

Upvotes: 3

Views: 2597

Answers (1)

Totem
Totem

Reputation: 7369

From the BoxLayout docs:

padding Added in 1.0.0 Padding between layout box and children: [padding_left, padding_top, padding_right, padding_bottom].

padding also accepts a two argument form [padding_horizontal, padding_vertical] and a one argument form [padding].

Changed in version 1.7.0: Replaced NumericProperty with VariableListProperty.

padding is a VariableListProperty and defaults to [0, 0, 0, 0].

Try adding a padding to the bottom of the boxlayout if you want it's children to get pushed toward the top.

for instance giving the padding a value of

[20, 20, 20, 'new bottom padding here']

Upvotes: 1

Related Questions