# Grid (Python)

Tiffany Antopolski
tiffany.antopolski@gmail.com 2012
Marta Maria Casetti
mmcasetti@gmail.com 2012
Pack widgets in rows and columns

# Grid

Some labels in a grid.

# Code used to generate this example

# Useful methods for a Grid widget

To attach a widget `child` in position `left, top` in a slot of given `width, height` use `attach(child, top, left, width, height)`. If a widget `sibling` is already in place, we can also use `attach_next_to(child, sibling, side, width, height)`, where `side` is one of `Gtk.PositionType.LEFT, Gtk.PositionType.RIGHT, Gtk.PositionType.TOP, Gtk.PositionType.BOTTOM`.

`insert_row(position)` and `insert_column(position)` do exactly what they say; children which are attached at or below this position are moved one row down, and children which span across this position are grown to span the new row. `insert_next_to(sibling, side)` inserts a row or column at the specified position. The new row or column is placed next to `sibling`, on the side determined by `side`; if side is `Gtk.PositionType.TOP` or `Gtk.PositionType.BOTTOM`, a row is inserted, if side is `Gtk.PositionType.LEFT` or `Gtk.PositionType.RIGHT`, a column is inserted.

`set_row_homogeneous(True)` and `set_column_homogeneous(True)` ensure that (respectively) every row or every column has the same width or height.

`set_row_spacing(spacing)` and `set_column_spacing(spacing)` force a spacing between (respectively) rows or columns. The value of `spacing` can be between `0`, which is the default value, and `32767`.

# API References

In this sample we used the following:

GtkApplication

GtkApplicationWindow

GtkLabel

GtkImage

GtkGrid