Methods

Widget Methods

The following methods are available on widgets managed by the grid manager:

grid(option=value, ...), grid_configure(option=value, ...)

Place the widget in a grid as described by the options (see below).

grid_forget()

Remove the widget. The widget is not destroyed, and can be displayed again by grid or any other manager.

grid_info() => dictionary

Return a dictionary containing the current options.

grid_remove()

Remove the widget. The widget is not destroyed, and can be displayed again by grid or any other manager.

Manager Methods

The following methods are available on widgets that are used as grid managers (that is, the geometry masters for widgets managed by the grid manager).

columnconfigure(column, option=value, ...), rowconfigure(row, option=value, ...)

Set options for the given column (or row).

To change this for a given widget, you have to call this method on the widget's parent.

Table 27-1. Grid Manager Options

Option

Type

Description

minsize

integer

Defines the minimum size for the column (row). Note that if a column or row is completely empty, it will not be displayed, even if this option is set.

pad

integer

Padding to add to the size of the largest widget in the column (row) when setting the size of the whole column.

weight

integer

A relative weight used to distribute additional space between columns (rows). A column with the weight 2 will grow twice as fast as a column with weight 1. The default is 0, which means that the column will not grow at all.

grid_location(x, y) => tuple

Returns the grid cell under (or closest to) the given pixel coordinate. The result is a 2-tuple: (column, row).

grid_propagate(flag)

Enables or disables geometry propagation. When enabled, the grid manager attempts to change the size of the geometry master when a child widget changes size. Propagation is always enabled by default.

grid_size() => tuple

Returns the current grid size. This is defined as indexes of the first empty column and row in the grid, in that order. The result is a 2-tuple: (column, row).

grid_slaves() => list

Returns a list of the "slave" widgets managed by this widget. The widgets are returned as Tkinter widget references.