Grid#

The grid geometry manager places a widget in a row/column grid in its parent. This page is the method spec; Arranging widgets teaches when to reach for grid.

In ttkbootstrap grid (and grid_configure) return the widget, so construction and placement can be chained.

The canonical upstream reference is the Tk grid manual page (Tcl 8.6).

Options#

Every option below is a keyword argument to grid().

Option

Type

Description

row
column

int

The cell to occupy (0-based). column defaults to 0; row defaults to the first empty row.

rowspan
columnspan

int

How many rows / columns the widget covers. Default 1.

sticky

str

Which sides of the cell the widget sticks to — any combination of "nsew". Opposite pairs stretch the widget; the default centers it at its natural size.

padx
pady

int | tuple

External space around the widget, in pixels. A (left, right) / (top, bottom) tuple pads the two sides differently.

ipadx
ipady

int

Internal padding added to the widget’s own size, in pixels.

in_

Widget

Grid inside a container other than the parent (the container must be the parent or one of its descendants). Rarely needed.

Placing a widget#

grid(**options)

Place the widget in a cell (or span of cells), using the options above. Alias: grid_configure.

Returns:

the widget (ttkbootstrap), for chaining.

grid_forget()

Unmap the widget and forget its grid options.

Returns:

None.

grid_remove()

Unmap the widget but remember its options, so a later grid() with no arguments restores it in place.

Returns:

None.

grid_info()

Return the widget’s current grid options.

Return type:

dict

Configuring the container#

These are called on the parent to shape its rows and columns — most importantly weight, which decides how leftover space is shared when the window resizes.

columnconfigure(index, **options)

Configure a column of this container’s grid. Alias: grid_columnconfigure.

Parameters:
  • index – the column number (or a list of them).

  • optionsweight (share of extra space), minsize, pad, uniform (columns sharing a group grow together).

Returns:

the current settings when queried, else None.

rowconfigure(index, **options)

Configure a row of this container’s grid. Alias: grid_rowconfigure. Takes the same options as columnconfigure().

Parameters:

index – the row number (or a list of them).

Returns:

the current settings when queried, else None.

grid_propagate(flag=None)

Get or set whether this container resizes to fit its gridded children. Set False to keep a fixed size.

Parameters:

flag (bool) – the new setting; omit to query.

Returns:

the current setting when queried, else None.

grid_size()

Return the container’s grid size as (columns, rows).

Return type:

tuple[int, int]

grid_slaves(row=None, column=None)

Return the widgets this container manages with grid, optionally filtered to a row and/or column.

Return type:

list

grid_location(x, y)

Return the (column, row) cell that covers a pixel coordinate.

Return type:

tuple[int, int]

grid_bbox(column=None, row=None, col2=None, row2=None)

Return the bounding box (x, y, width, height) of a cell or a span of cells, in pixels.

Return type:

tuple[int, int, int, int]

grid_anchor(anchor=None)

Get or set where the whole grid is anchored inside the container when it is larger than the grid.

Parameters:

anchor – an anchor like "center" or "nw"; omit to query.