Gtk.Grid
Gtk.Grid — Pack widgets in a rows and columns
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Container
╰── Gtk.Grid
See also:
Functions:
- new
() -> Gtk.Widget
- attach
(self, child:Gtk.Widget, left:int, top:int, width:int, height:int)
- attach_next_to
(self, child:Gtk.Widget, sibling:Gtk.Widget=None, side:Gtk.PositionType, width:int, height:int)
- get_child_at
(self, left:int, top:int) -> Gtk.Widget or None
- insert_row
(self, position:int)
- insert_column
(self, position:int)
- remove_row
(self, position:int)
- remove_column
(self, position:int)
- insert_next_to
(self, sibling:Gtk.Widget, side:Gtk.PositionType)
- set_row_homogeneous
(self, homogeneous:bool)
- get_row_homogeneous
(self) -> bool
- set_row_spacing
(self, spacing:int)
- get_row_spacing
(self) -> int
- set_column_homogeneous
(self, homogeneous:bool)
- get_column_homogeneous
(self) -> bool
- set_column_spacing
(self, spacing:int)
- get_column_spacing
(self) -> int
- get_baseline_row
(self) -> int
- set_baseline_row
(self, row:int)
- get_row_baseline_position
(self, row:int) -> Gtk.BaselinePosition
- set_row_baseline_position
(self, row:int, pos:Gtk.BaselinePosition)
Description:
Gtk.Grid
is a container which arranges its child widgets in rows and columns. It is a very similar to GtkTable and Gtk.Box, but it consistently uses Gtk.Widget’s Gtk.Widget:margin and Gtk.Widget:expand properties instead of custom child properties, and it fully supports [height-for-width geometry management][geometry-management]
.
Children are added using Gtk.Grid::attach()
. They can span multiple rows or columns. It is also possible to add a child next to an existing child, using Gtk.Grid::attach_next_to()
. The behaviour of Gtk.Grid
when several children occupy the same grid cell is undefined.
Gtk.Grid
can be used like a GtkBox by just using Gtk.Container::add()
, which will place children next to each other in the direction determined by the Gtk.Orientable::orientation
property.
Function Details:
new()
new () -> Gtk.Widget
Creates a new grid widget.
- Returns: the new Gtk.Grid
attach()
attach (self, child:Gtk.Widget, left:int, top:int, width:int, height:int)
Adds a widget to the grid.
The position of child
is determined by left
and top
. Thenumber of “cells” that child
will occupy is determined bywidth
and height
.
attach_next_to()
attach_next_to (self, child:Gtk.Widget, sibling:Gtk.Widget=None, side:Gtk.PositionType, width:int, height:int)
Adds a widget to the grid.
The widget is placed next to sibling
, on the side determined byside
. When sibling
is None
, the widget is placed in row (forleft or right placement) or column 0 (for top or bottom placement),at the end indicated by side
.
Attaching widgets labeled [1], [2], [3] with sibling
== None
andside
== GTK_POS_LEFT
yields a layout of 3[1].
get_child_at()
get_child_at (self, left:int, top:int) -> Gtk.Widget or None
Gets the child of grid
whose area covers the gridcell whose upper left corner is at left
, top
.
Returns: the child at the given position, or
None
.Since: 3.2
insert_row()
insert_row (self, position:int)
Inserts a row at the specified position. Children which are attached at or below this positionare moved one row down. Children which span across thisposition are grown to span the new row.
- Since: 3.2
insert_column()
insert_column (self, position:int)
Inserts a column at the specified position. Children which are attached at or to the right of this positionare moved one column to the right. Children which span across thisposition are grown to span the new column.
- Since: 3.2
remove_row()
remove_row (self, position:int)
Removes a row from the grid. Children that are placed in this row are removed,spanning children that overlap this row have theirheight reduced by one, and children below the roware moved up.
- Since: 3.10
remove_column()
remove_column (self, position:int)
Removes a column from the grid. Children that are placed in this column are removed,spanning children that overlap this column have theirwidth reduced by one, and children after the columnare moved to the left.
- Since: 3.10
insert_next_to()
insert_next_to (self, sibling:Gtk.Widget, side:Gtk.PositionType)
Inserts a row or column at the specified position.
The new row or column is placed next to sibling
, on the sidedetermined by side
. If side
is GTK_POS_TOP
or GTK_POS_BOTTOM
,a row is inserted. If side
is GTK_POS_LEFT
of GTK_POS_RIGHT
,a column is inserted.
- Since: 3.2
set_row_homogeneous()
set_row_homogeneous (self, homogeneous:bool)
Sets whether all rows of grid
will have the same height.
get_row_homogeneous()
get_row_homogeneous (self) -> bool
Returns whether all rows of grid
have the same height.
- Returns:
whether all rows of
grid
have the same height.
set_row_spacing()
set_row_spacing (self, spacing:int)
Sets the amount of space between rows of grid
.
get_row_spacing()
get_row_spacing (self) -> int
Returns the amount of space between the rows of grid
.
- Returns:
the row spacing of
grid
set_column_homogeneous()
set_column_homogeneous (self, homogeneous:bool)
Sets whether all columns of grid
will have the same width.
get_column_homogeneous()
get_column_homogeneous (self) -> bool
Returns whether all columns of grid
have the same width.
- Returns:
whether all columns of
grid
have the same width.
set_column_spacing()
set_column_spacing (self, spacing:int)
Sets the amount of space between columns of grid
.
get_column_spacing()
get_column_spacing (self) -> int
Returns the amount of space between the columns of grid
.
- Returns:
the column spacing of
grid
get_baseline_row()
get_baseline_row (self) -> int
Returns which row defines the global baseline of grid
.
Returns: the row index defining the global baseline
Since: 3.10
set_baseline_row()
set_baseline_row (self, row:int)
Sets which row defines the global baseline for the entire grid.Each row in the grid can have its own local baseline, but onlyone of those is global, meaning it will be the baseline in theparent of the grid
.
Returns: the row index defining the global baseline
Since: 3.10
get_row_baseline_position()
get_row_baseline_position (self, row:int) -> Gtk.BaselinePosition
Returns the baseline position of row
as setby Gtk.Grid:set_row_baseline_position()
or the default valueGTK_BASELINE_POSITION_CENTER
.
Returns: the baseline position of
row
Since: 3.10
set_row_baseline_position()
set_row_baseline_position (self, row:int, pos:Gtk.BaselinePosition)
Sets how the baseline should be positioned on row
of thegrid, in case that row is assigned more space than is requested.
- Since: 3.10
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class Grid(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("Grid")
self.connect("destroy", Gtk.main_quit)
grid = Gtk.Grid()
grid.set_row_spacing(5)
grid.set_column_spacing(5)
self.add(grid)
button = Gtk.Button(label="Button 1")
grid.attach(button, 0, 0, 1, 2)
button = Gtk.Button(label="Button 2")
grid.attach(button, 1, 0, 1, 1)
button = Gtk.Button(label="Button 3")
grid.attach(button, 2, 0, 1, 1)
button = Gtk.Button(label="Button 4")
grid.attach(button, 1, 1, 2, 1)
window = Grid()
window.show_all()
Gtk.main()