Skip to content

GridFrame

Bases: Frame

A Frame with simplified grid-based layout management and auto-placement.

GridFrame extends the bootstack Frame with automatic grid-based layout management, including support for row/column definitions, gap spacing, auto-placement, and default sticky behavior.

Children gridded into this frame automatically receive the frame's default layout options. Simply use the standard grid() method on child widgets — no special add() method is needed.

Example
frame = GridFrame(columns=3, gap=10, sticky_items="nsew")
Label(frame, text="A").grid()  # auto-placed at row=0, col=0
Label(frame, text="B").grid()  # auto-placed at row=0, col=1
Label(frame, text="C").grid()  # auto-placed at row=0, col=2
Label(frame, text="D").grid()  # auto-placed at row=1, col=0
Label(frame, text="Wide").grid(columnspan=2)  # spans 2 columns

__init__

__init__(
    master: Master = None,
    *,
    rows: Optional[
        Union[int, list[Union[int, str]]]
    ] = None,
    columns: Optional[
        Union[int, list[Union[int, str]]]
    ] = None,
    gap: Gap = 0,
    sticky_items: Optional[Sticky] = None,
    propagate: Optional[bool] = None,
    auto_flow: AutoFlow = "row",
    **kwargs: Any,
) -> None

Create a GridFrame with automatic grid-based layout.

Parameters:

Name Type Description Default
master Master

Parent widget. If None, uses the default root window.

None
rows Optional[Union[int, list[Union[int, str]]]]

Number of rows as an int, or a list of size specs where each spec is an int weight or a string such as 'auto' or '100px'.

None
columns Optional[Union[int, list[Union[int, str]]]]

Number of columns or a list of size specs (same format as rows).

None
gap Gap

Spacing between cells. An int applies the same gap in both directions; a (col_gap, row_gap) tuple sets them independently.

0
sticky_items Optional[Sticky]

Default sticky value applied to all children when they call grid(). If None, no default sticky is applied.

None
propagate Optional[bool]

If False, the frame will not resize to fit its contents. Defaults to None (Tk default behaviour).

None
auto_flow AutoFlow

Auto-placement mode — 'row' (default), 'column', 'row-dense', 'column-dense', or 'none'.

'row'
**kwargs Any

Additional keyword arguments forwarded to Frame.

{}

configure_row

configure_row(
    index: int,
    weight: int = 1,
    minsize: Optional[int] = None,
    pad: Optional[int] = None,
) -> None

Configure a row's properties.

configure_column

configure_column(
    index: int,
    weight: int = 1,
    minsize: Optional[int] = None,
    pad: Optional[int] = None,
) -> None

Configure a column's properties.