Reputation: 55
So I'm very new to KIVY and I'm trying to make a simple menu sort of thing. The python file is:
from kivy.app import App
class MenuApp(APP):
pass
MenuApp().run()
and the kivy file:
Interface:
<Interface@BoxLayout>:
Label:
text: "logo"
BoxLayout:
orientation: "vertical"
BoxLayout:
Button:
text: "b1"
size_hint: .3, 1
Button:
text: "b2"
Button:
text: "b3"
size_hint: .3, 1
pos_hint: {"center_x": 0.5}
Button:
text: "b4"
size_hint: .3, 1
pos_hint: {"right": 1}
The problem comes from buttons "b1" and "b2". when I give them a size_hint it doesn't change anything. The size_hints on the rest work and these 2 work when i take them out of their BoxLayout. Is this just a thing? that you cant put boxlayers inside 2 other boxlayers? or am I doing something wrong?
Upvotes: 0
Views: 921
Reputation: 39117
from the BoxLayout documentation::
The size_hint uses the available space after subtracting all the fixed-size widgets.
So the BoxLayout
divides the available space according to the size_hint
value. In your code the b1
Button has size_hint
of .3
, while b2
has the default size_hint
of 1.0
. The sharing algorithm then gives b1
a 0.3/(1.0+0.3)
(or 0.230769
) share of the available space, and b2
gets 1.0/(1.0+0.3)
(or 0.769231
) share of the available space. You must consider the size_hints
of both of the Buttons
, including the default values if you don't assign one.
Upvotes: 1