Skip to content

Grid

This capability documents one focused aspect of the widget interface (Tk/Tcl-style behavior + bootstack extensions).

Note: You typically won’t use bootstack.core.capabilities.grid directly. This page describes the behavior that widgets expose.

Grid geometry manager helpers (grid).

Tk's grid geometry manager arranges widgets in a table of rows and columns.

In bootstack v2 you may prefer higher-level layout containers (e.g. GridFrame) for most UI layout. This mixin documents the underlying Tkinter grid_* API as an escape hatch and for interoperability with existing Tk code.

Notes
  • grid() attaches a widget to a parent container that is using grid.
  • rowconfigure() / columnconfigure() set sizing behavior (weight/minsize/pad).
  • grid_propagate(False) prevents a container from resizing to fit its children.
  • If the parent has a _on_child_grid hook (e.g. GridFrame), layout defaults are applied automatically.

grid

grid(cnf: dict[str, Any] | None = None, **kw: Any) -> Self

Position this widget using the grid geometry manager.

Parameters:

Name Type Description Default
cnf dict[str, Any] | None

Optional dict of grid options.

None
**kw Any

Grid options. Common options include: - row, column: Cell coordinates (0-based). - rowspan, columnspan: Span across multiple cells. - sticky: How the widget expands within its cell (e.g. "nsew"). - padx, pady: External padding around the widget. - ipadx, ipady: Internal padding inside the widget.

{}

Returns:

Type Description
Self

Self for method chaining.

grid_configure

grid_configure(
    cnf: dict[str, Any] | None = None, **kw: Any
) -> Self

Alias for grid().

Parameters:

Name Type Description Default
cnf dict[str, Any] | None

Optional dict of grid options.

None
**kw Any

Grid options (see grid).

{}

Returns:

Type Description
Self

Self for method chaining.

grid_forget

grid_forget() -> Self

Unmap this widget and forget its grid configuration.

The widget is removed from the layout, and its previous grid options are discarded.

Returns:

Type Description
Self

Self for method chaining.

grid_remove

grid_remove() -> Self

Unmap this widget but remember its grid configuration.

Use grid() with no args to restore it to its previous grid location.

Returns:

Type Description
Self

Self for method chaining.

grid_info

grid_info() -> dict[str, Any]

Return this widget's current grid configuration.

Returns:

Type Description
dict[str, Any]

A dict containing the current grid options for this widget

dict[str, Any]

(row, column, sticky, padx, pady, etc.).

grid_propagate

grid_propagate(flag: bool | None = None) -> bool | None

Get or set grid geometry propagation for this container.

When propagation is enabled (default), the container may resize itself to fit the size requests of its children.

Parameters:

Name Type Description Default
flag bool | None

True/False to enable/disable propagation. If None, acts as a getter.

None

Returns:

Type Description
bool | None

When queried, returns the current propagation flag. When set, returns None.

grid_rowconfigure

grid_rowconfigure(
    index: int, cnf: dict[str, Any] | None = None, **kw: Any
) -> None

Configure sizing behavior for a grid row in this container.

Common options
  • weight: How extra space is distributed (0 means no expansion).
  • minsize: Minimum row size in pixels.
  • pad: Extra padding added to the row.

Parameters:

Name Type Description Default
index int

Row index (0-based).

required
cnf dict[str, Any] | None

Optional dict of configuration options.

None
**kw Any

Row configuration options.

{}

grid_columnconfigure

grid_columnconfigure(
    index: int, cnf: dict[str, Any] | None = None, **kw: Any
) -> None

Configure sizing behavior for a grid column in this container.

Common options
  • weight: How extra space is distributed (0 means no expansion).
  • minsize: Minimum column size in pixels.
  • pad: Extra padding added to the column.

Parameters:

Name Type Description Default
index int

Column index (0-based).

required
cnf dict[str, Any] | None

Optional dict of configuration options.

None
**kw Any

Column configuration options.

{}

grid_size

grid_size() -> tuple[int, int]

Return the grid size (columns, rows) used in this container.

Returns:

Type Description
tuple[int, int]

A tuple (num_columns, num_rows).

grid_slaves

grid_slaves(
    row: int | None = None, column: int | None = None
) -> list[Any]

Return the widgets managed by grid in this container.

Parameters:

Name Type Description Default
row int | None

If provided, return only widgets in the given row.

None
column int | None

If provided, return only widgets in the given column.

None

Returns:

Type Description
list[Any]

A list of child widgets managed by grid.