Grid Helper
Cell
dataclass
Cell contains configuration for placing a widget in a grid, which will be passed to the .grid()
method.
Source code in tkinter_layout_helpers/grid_helper.py
set_column_span(span)
Set the number of columns to span for the widget in the cell.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
span
|
int
|
number of columns to span |
required |
set_row_span(span)
Set the number of rows to span for the widget in the cell.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
span
|
int
|
number of rows to span |
required |
Column
Virtual column object of a grid to configure "real" columns in the grid.
Source code in tkinter_layout_helpers/grid_helper.py
__init__(grid, index)
configure(*args, **kwargs)
Configure the column of a grid. See .grid_columnconfigure()
documentation of tkinter for details.
Columns
Proxy object to configure columns of a grid.
Source code in tkinter_layout_helpers/grid_helper.py
__getitem__(index)
Get a column object by index.
Source code in tkinter_layout_helpers/grid_helper.py
__init__(grid)
Grid
Bases: Generic[TParent]
Builder class to create a grid of widgets.
Source code in tkinter_layout_helpers/grid_helper.py
columns
property
Get a proxy object to configure the columns of a grid.
__init__(parent, **kwargs)
Initialize Grid object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent
|
TParent
|
parent widget |
required |
kwargs
|
common parameters to configure the widgets of a grid.
Common parameters have lower priority than parameters set by |
{}
|
Source code in tkinter_layout_helpers/grid_helper.py
build()
Build a grid. Call this method after all widgets have been added to the grid.
Source code in tkinter_layout_helpers/grid_helper.py
columnconfigure(i, *args, **kwargs)
Configure the column of a grid. See .grid_columnconfigure()
documentation of tkinter for details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i
|
int
|
column index |
required |
args
|
additional parameters to configure the column |
()
|
|
kwargs
|
additional parameters to configure the column |
{}
|
Source code in tkinter_layout_helpers/grid_helper.py
new_row()
rowconfigure(i, *args, **kwargs)
Configure the row of a grid. See .grid_rowconfigure()
documentation of tkinter for details.
Row
dataclass
Bases: AbstractContextManager
Row contains a list of cells, which will be passed to the .grid()
method.
Source code in tkinter_layout_helpers/grid_helper.py
__enter__()
__exit__(exc_type, exc_value, traceback)
add(widget, **kwargs)
Add a widget to a row of a grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget
|
Widget
|
widget to add |
required |
kwargs
|
all additional parameters to configure the widget's position in the cell |
{}
|
Source code in tkinter_layout_helpers/grid_helper.py
configure(*args, **kwargs)
Configure the row of a grid. See .grid_rowconfigure()
documentation of tkinter for details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
additional parameters to configure the row |
()
|
|
kwargs
|
additional parameters to configure the row |
{}
|
Source code in tkinter_layout_helpers/grid_helper.py
skip(count)
Skip a number of cells in a row of a grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count
|
int
|
number of columns to skip |
required |
grid_manager(parent, **kwargs)
A context manager to create a grid of widgets. It is intended to simplify a placement of widgets with .grid()
.
Basicly, it is a wrapper around Grid
class, but additionaly, it sets the parent widget of a grid
(within the with
statement scope), so you don't need to specify it explicitly for every widget.
Usage example:
with grid_manager(root, sticky=tk.EW) as grid:
with grid.new_row() as row:
row.add(tk.Label(text="0", width=20))
row.add(tk.Label(text="1", width=20))
row.add(tk.Label(text="2", width=20))
row.add(tk.Label(text="3", width=20))
row.add(tk.Label(text="4", width=20))