I was was wondering if I get get an explanation on how size_hint works in Kivy. From my understanding, it is the relative scale from the widget, to its parent layout. I tried the following code:
class TestFrame(GridLayout):
def __init__(self, **kwargs):
GridLayout.__init__(self, **kwargs)
self.rows = 1
self.add_widget(Label(text='test_num', size=(100, 25), size_hint=(.10, None)))
self.add_widget(Label(text='test_txt', size=(100, 25), size_hint=(.75, None)))
self.add_widget(Button(text='test_btn', size=(100, 25), size_hint=(.15, None)))
This is what I expect:
|----------------------------------------------------------------------|
|Test_num : Test_txt : Test_btn |
Instead this is the result:
|----------------------------------------------------------------------|
| Test_num : Test_txt : Test_btn |
I've played with different combinations of size_hint and size and end up with very similar results. What am I missing or not understanding?
As far as I am aware, use of
size_hint
ANDsize
are incompatible, when you set them for the same attribute, as in setting x or y for both. Use one or the other. If you think about it, it makes sense. Withsize
, you are explicitly setting a size for the widget, and withsize_hint
, you are also explicitly setting a size for the widget, just in a different way, that being relative to the widgets parent. So if you use both for the same attribute, x or y, they are bound to conflict.Exceptions here are probably when you have for instance,
size_hint_y
set to None, like you do above, and then specify asize
for y. Or if you setsize_hint_x
to None, and only specified asize
for x.However, above you have set the
size
of x, and thesize_hint
of x in all instances.So: These should be ok
These would conflict