Don't understand why the button does not occupy the entire screen, even though the size hint is (1,1)

11 views
Skip to first unread message

Filat Nicolae

unread,
Dec 26, 2020, 9:44:51 AM12/26/20
to Kivy users support
The kv file is simple
<MovieScreen>
Button:
on_press: print(root.size,self.size_hint)
pos_hint: {"x": 0, "y": 0}
background_color: 1,0,0,1

And the main.py looks something like this

class MovieScreen(Widget):
pass


class MovieApp(App):
def build(self):
return MovieScreen()
MovieApp().run()

As I understand it Movie Screen has a size of (800,600) and the button having size_hint (1,1) by default should occupy
the entire space given right? The Button ends up being at pos (0,0) and having an unexpected size of (100,100)

The docs say that any widget has a default size of (100,100) and a size_hint of (1,1) but which one is respected first?
As I understand size_hint and position_hint position the widget based on parent widget.



Elliot Garbus

unread,
Dec 26, 2020, 9:52:28 AM12/26/20
to kivy-...@googlegroups.com

A widget in a Layout, not in another Widget. Change your definition of MovieScreen to be a Layout.

If you want the size and pos of the Button to be honored, use a FloatLayout.

If you want to use the size of the widget, set the size_hint to None, None

 

Size and position are a function of the Layout used.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/283a98cb-7d7c-4b03-bb85-d2d90b68ab12o%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages