BoxLayout(orientation='vertical')
vs. GridLayout(cols=1)
:
They both do the same thing, no? Is there a reason to choose one over the other?
BoxLayout(orientation='vertical')
vs. GridLayout(cols=1)
:
They both do the same thing, no? Is there a reason to choose one over the other?
The differences involves size and position.
In general, GridLayout
(cols: 1
) is always going to keep the elements in one column, whereas there is more flexibility to organize individual widgets when you use BoxLayout
(orientation: 'vertical'
).
Here is a very simple example of something you can do with BoxLayout
because it honours pos_hint
, size
and size_hint
(and others such as center_x
, x
, y
, right
, - notice that they also depend on the vertical
or horizontal
orientation of the BoxLayout
) which affects individual widgets:
<Test@BoxLayout>:orientation: 'vertical'Button:text: 'a'size_hint: None, Nonesize: 100,50pos_hint: { 'center_x' : .5 }Button:text: 'b'
This is the output in a 200x200 screen:
If you attempt to do the same but using GridLayout
instead, then you get this:
Finally, GridLayout
has some properties to control the size of the column:
col_default_width
: for the default width of all the columnscol_width
: a list of widths for each column (not useful in this
case since we have just one) col_force_default
: which will ignore any existing size_hint
or size
for individual widgets and force the column widthminimum_width
: so the column not shrink too much