How to make a widget span multiple columns/rows in gridlayout in kivy

10,890

Solution 1

I don't think a GridLayout is really suitable, it just isn't designed for quite that usage.

If I personally had to do this, I'd probably make my own Layout class, it wouldn't need a very complicated do_layout method.

One possible start point would be the SparseGridLayout I made a while ago. You could very easily add column and row span properties to it...actually, I'll probably add them myself now that you've given me the idea!

That might not be ideal if you have a big grid full of widgets, in which case something similar to a gridlayout might be better, or possibly a combination of multiple layouts if the spanning widgets are in a particular pattern.

Solution 2

Another option here is to have a GridLayout with 1 column and populate each row with a BoxLayout with orientation="horizontal". You can then format each BoxLayout (row) as you want.

For more info on the BoxLayout: http://kivy.org/docs/api-kivy.uix.boxlayout.html

Share:
10,890
user3299143
Author by

user3299143

Updated on July 26, 2022

Comments

  • user3299143
    user3299143 almost 2 years

    I would like to create an app in kivy with widgets in a grid and I want to be able to set some widgets to be larger - to occupy more than one cell in a grid.

    GridLayout seems the most appropriate, but it seems to not support placing widgets in more than one cell.

    To be more specific I want behavour similar to the grid geometry manager from Tkinter, when setting columnspan or rowspan to more than 1.

    Like this:

    (widget)(widget)(widget)
    ( bigger widget )(widget)
    ...
    

    I would prefer to be able to do this using existing kivy layouts instead of having to write my own layout class to handle this, but if no other option is possible, this is also ok.