GroupBox#
A labelled container that groups related content inside a bordered frame.
The title is embedded in the top border line, giving the classic fieldset
look familiar from HTML <fieldset> and desktop dialog panels.
Usage#
Accent borders#
Pass an accent= token to color the border and title label. The title text
automatically inherits the accent color.
with bs.GroupBox("Primary", accent="primary", padding=20, gap=16):
bs.Label("Item one")
bs.Label("Item two")
Layout modes#
layout='vstack' (default) stacks children vertically. 'hstack' places
them side by side. 'grid' arranges children in a column-row grid.
# Default vertical stack
with bs.GroupBox("Details", gap=8):
bs.Label("First")
bs.Label("Second")
# Horizontal stack
with bs.GroupBox("Steps", layout="hstack", gap=12, anchor_items="center"):
bs.Label("A")
bs.Label("B")
bs.Label("C")
# Grid — two columns, key/value pairs
with bs.GroupBox("Info", layout="grid", columns=[1, 1], gap=8, sticky_items="ew"):
bs.Label("Name:") ; bs.Label("Ada Lovelace")
bs.Label("Role:") ; bs.Label("Engineer")
Child defaults#
Use fill_items, expand_items, and anchor_items to apply a uniform
layout behavior to all children without repeating it on each widget.
with bs.GroupBox("Filters", gap=8, fill_items="x"):
bs.TextField() # fills horizontally by default
bs.TextField()
In context#
GroupBox is commonly used to visually separate settings panels or summary sections within a larger form or dashboard.
with bs.GroupBox("Connection", accent="primary", padding=12, gap=8):
with bs.HStack(gap=8):
bs.Label("Host:")
bs.Label("localhost")
with bs.HStack(gap=8):
bs.Label("Status:")
bs.Label("Connected", accent="success")
Widget sizing#
All widgets accept self-placement kwargs via **kwargs. The parent
container determines which options apply — stack-based parents use stack
kwargs, grid-based parents use grid kwargs. Unrecognised keys are
silently ignored.
Stack#
Used inside VStack, HStack, App, and other stack containers.
|
Fill direction: |
|
Grow to consume extra space in the parent. |
|
Alignment when the widget does not fill the available slot:
|
|
External spacing in pixels. Accepts an integer (equal on all
sides), a 2-tuple |
|
Horizontal external spacing (left and right). Accepts an integer
or a 2-tuple |
|
Vertical external spacing (top and bottom). Accepts an integer
or a 2-tuple |
Grid#
Used inside a Grid container.
|
Zero-based row and column indices. |
|
Number of rows or columns to span. |
|
Alignment and fill within the grid cell. Any combination of
|
|
External spacing in pixels. Accepts an integer, a 2-tuple
|
|
Horizontal external spacing. Accepts an integer or |
|
Vertical external spacing. Accepts an integer or |
See also#
VStack,
HStack, and
Grid are the plain (no border) layout
containers. Use GroupBox when you want a labelled border around a group
of related content.
API#
The complete reference for GroupBox lives on the
Widgets API page. At a glance:
A labeled container that groups related content inside a bordered frame. |
Full Example#
1
2with bs.App(title="GroupBox Demo", padding=20, gap=16) as app:
3
4 # Accent borders
5 bs.Label("Accent Borders", font="heading-sm")
6 with bs.HStack(gap=12, anchor_items="n"):
7 for accent in ("default", "primary", "secondary", "success", "warning", "danger"):
8 with bs.GroupBox(accent.title(), accent=accent, padding=10, gap=4):
9 bs.Label("Item one")
10 bs.Label("Item two")
11
12 # Layout modes
13 bs.Label("Layout Modes", font="heading-sm")
14 with bs.HStack(gap=12, anchor_items="n"):
15
16 with bs.GroupBox("VStack (default)", padding=10, gap=8):
17 bs.Label("First")
18 bs.Label("Second")
19 bs.Label("Third")
20
21 with bs.GroupBox("HStack", layout="hstack", padding=10, gap=12, anchor_items="center"):
22 bs.Label("A")
23 bs.Label("B")
24 bs.Label("C")
25
26 with bs.GroupBox("Grid", layout="grid", columns=[1, 1], padding=10, gap=8, sticky_items="ew"):
27 bs.Label("Name:")
28 bs.Label("Ada Lovelace")
29 bs.Label("Role:")
30 bs.Label("Engineer")
31
32 # In context
33 bs.Label("In Context", font="heading-sm")
34 with bs.HStack(gap=12, anchor_items="n"):
35
36 with bs.GroupBox("Connection", accent="primary", padding=12, gap=8):
37 with bs.HStack(gap=8, anchor_items="center"):
38 bs.Label("Host:")
39 bs.Label("localhost")
40 with bs.HStack(gap=8, anchor_items="center"):
41 bs.Label("Port:")
42 bs.Label("5432")
43 with bs.HStack(gap=8, anchor_items="center"):
44 bs.Label("Status:")
45 bs.Label("Connected", accent="success")
46
47 with bs.GroupBox("Alerts", accent="warning", padding=12, gap=6):
48 bs.Label("Disk usage above 80%", accent="warning")
49 bs.Label("2 services degraded", accent="danger")
50 bs.Label("Backup completed", accent="success")
51
52app.run()