CommandBar#

A horizontal strip of buttons, labels, separators, and other widgets. Items are added left-to-right via add_button(), add_label(), add_separator(), add_spacer(), and add_widget().

CommandBar demo — light theme CommandBar demo — dark theme

Usage#

Adding buttons#

Pass label= for text, icon= for an icon, or both for a text-and-icon button. Omit label= to get an icon-only button.

tb = bs.CommandBar(fill="x")

tb.add_button("Save", icon="floppy")           # text + icon
tb.add_button(icon="gear")                      # icon-only
tb.add_button("Cancel")                         # text-only

Use on_click= to attach a callback, and accent= to apply a color intent to individual buttons.

tb.add_button("Publish", icon="cloud-upload", accent="primary", on_click=publish)
tb.add_button("Discard", icon="trash", accent="danger", on_click=discard)
CommandBar accent buttons — light theme CommandBar accent buttons — dark theme

Separators and spacers#

add_separator() inserts a thin vertical rule between item groups. add_spacer() inserts a flexible gap that pushes everything added after it to the right side.

tb.add_button("Bold", icon="type-bold")
tb.add_button("Italic", icon="type-italic")
tb.add_separator()
tb.add_button("Align left", icon="text-left")
tb.add_spacer()
tb.add_button(icon="gear")          # pinned to the right
CommandBar separators and spacers — light theme CommandBar separators and spacers — dark theme

Labels#

add_label() adds non-interactive text, optionally with an icon. Use it for the application name or section titles.

tb.add_label("My App", font="heading-md")
tb.add_separator()
tb.add_button("New", icon="file-earmark-plus")

Density#

density="compact" reduces padding and button size — useful for secondary command bars such as a rich-text formatting strip.

tb = bs.CommandBar(fill="x", density="compact")
tb.add_button(icon="type-bold")
tb.add_button(icon="type-italic")
tb.add_button(icon="type-underline")
CommandBar compact density — light theme CommandBar compact density — dark theme

Button variant#

button_variant= sets the default variant for all buttons added to the command bar. Override per-button with the variant= argument on add_button().

tb = bs.CommandBar(fill="x", button_variant="outline")
tb.add_button("Save", icon="floppy")        # outline
tb.add_button("Run", variant="solid")       # override to solid

Border and surface#

show_border=True draws a border around the command bar. surface= controls the background token — 'card' lifts it slightly from the page background.

tb = bs.CommandBar(fill="x", show_border=True, surface="card")
tb.add_button("New",  icon="file-earmark-plus")
tb.add_button("Open", icon="folder2-open")
tb.add_button("Save", icon="floppy")
CommandBar with border and card surface — light theme CommandBar with border and card surface — dark theme

Custom widgets#

Use add_widget() to embed any widget (e.g. a Select) in the command bar. Create the widget with the command bar as its parent first.

tb = bs.CommandBar(fill="x")
branch = bs.Select(
    ["main", "dev", "feat/new-ui"],
    parent=tb,
)
tb.add_widget(branch)

Custom titlebar#

Set show_window_controls=True to add minimize, maximize, and close buttons on the right, and draggable=True to let the user drag the window by the command bar. Pair with undecorated=True on the App to remove the OS title bar.

with bs.App(title="My App", undecorated=True) as app:
    tb = bs.CommandBar(
        fill="x",
        show_window_controls=True,
        draggable=True,
    )
    tb.add_label("My App", font="heading-md")
    tb.add_spacer()
    ...
app.run()

Command bar inside AppShell#

AppShell includes a built-in command bar. Access it via shell.commandbar and call the same add_* methods. Use command= (not on_click=) when calling add_button() on the AppShell command bar.

with bs.AppShell(title="My App") as shell:
    shell.commandbar.add_spacer()
    shell.commandbar.add_button(icon="circle-half", command=bs.toggle_theme)
    ...

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

Fill direction: 'x', 'y', 'both', or 'none'.

expand

Grow to consume extra space in the parent. True or False.

anchor

Alignment when the widget does not fill the available slot: 'n', 's', 'e', 'w', 'center', 'nw', etc.

margin

External spacing in pixels. Accepts an integer (equal on all sides), a 2-tuple (horizontal, vertical), or a 4-tuple (left, top, right, bottom).

margin_x

Horizontal external spacing (left and right). Accepts an integer or a 2-tuple (left, right) for asymmetric spacing. Overrides the horizontal component of margin=.

margin_y

Vertical external spacing (top and bottom). Accepts an integer or a 2-tuple (top, bottom) for asymmetric spacing. Overrides the vertical component of margin=.

Grid#

Used inside a Grid container.

row / column

Zero-based row and column indices.

rowspan / columnspan

Number of rows or columns to span.

sticky

Alignment and fill within the grid cell. Any combination of 'n', 's', 'e', 'w' — e.g. 'ew' stretches horizontally, 'nsew' fills the entire cell.

margin

External spacing in pixels. Accepts an integer, a 2-tuple (horizontal, vertical), or a 4-tuple (left, top, right, bottom).

margin_x

Horizontal external spacing. Accepts an integer or (left, right).

margin_y

Vertical external spacing. Accepts an integer or (top, bottom).

See also#

AppShell — full application scaffold with a built-in command bar, sidebar, and page stack.

Button — standalone button widget.

API#

The complete reference for CommandBar lives on the Widgets API page. At a glance:

CommandBar

A horizontal strip of buttons, labels, and other widgets.

Full Example#

 1
 2with bs.App(title="CommandBar demo", minsize=(700, 300), padding=16) as app:
 3
 4    with bs.VStack(fill="both", expand=True, gap=16):
 5
 6        # ── Default density ────────────────────────────────────────────────
 7        with bs.VStack(fill="x", padding=(16, 12, 16, 4)):
 8            bs.Label("Default", font="heading-sm")
 9
10            tb1 = bs.CommandBar(fill="x")
11            tb1.add_label("Editor", font="heading-md")
12            tb1.add_separator()
13            tb1.add_button("New", icon="file-earmark-plus")
14            tb1.add_button("Open", icon="folder2-open")
15            tb1.add_button("Save", icon="floppy")
16            tb1.add_spacer()
17            tb1.add_button(icon="circle-half", on_click=bs.toggle_theme)
18            tb1.add_button(icon="gear")
19
20        # ── Compact density ────────────────────────────────────────────────
21        with bs.VStack(fill="x", padding=(16, 12, 16, 4)):
22            bs.Label("Compact density", font="heading-sm")
23
24            tb2 = bs.CommandBar(fill="x", density="compact")
25            tb2.add_button(icon="type-bold")
26            tb2.add_button(icon="type-italic")
27            tb2.add_button(icon="type-underline")
28            tb2.add_separator()
29            tb2.add_button(icon="text-left")
30            tb2.add_button(icon="text-center")
31            tb2.add_button(icon="text-right")
32            tb2.add_separator()
33            tb2.add_button(icon="list-ul")
34            tb2.add_button(icon="list-ol")
35            tb2.add_spacer()
36            tb2.add_button(icon="arrow-counterclockwise")
37            tb2.add_button(icon="arrow-clockwise")
38
39        # ── Accents and variants ───────────────────────────────────────────
40        with bs.VStack(fill="x", padding=(16, 12, 16, 4)):
41            bs.Label("Accents and variants", font="heading-sm")
42            tb3 = bs.CommandBar(fill="x")
43            tb3.add_button("Publish", icon="cloud-upload", accent="primary")
44            tb3.add_button("Preview", icon="eye")
45            tb3.add_button("Draft", icon="pencil")
46            tb3.add_spacer()
47            tb3.add_button("Discard", icon="trash", accent="danger")
48
49        # ── Border & Surface ────────────────────────────────────────────────
50        with bs.VStack(fill="x", padding=(16, 12, 16, 4)):
51            bs.Label("Border and Surface", font="heading-sm")
52
53            tb1 = bs.CommandBar(fill="x", show_border=True, surface="card")
54            tb1.add_button("New", icon="file-earmark-plus")
55            tb1.add_button("Open", icon="folder2-open")
56            tb1.add_button("Save", icon="floppy")
57
58
59app.run()