ButtonGroup
ButtonGroup groups related actions into a connected row or column of buttons.
It is most common in toolbars, segmented controls, and compact "action clusters" where buttons should read as a unit.
Quick start
Create a group and add buttons. The group handles spacing, connection visuals, and consistent styling.
import bootstack as bs
app = bs.App()
bg = bs.ButtonGroup(app, accent="primary")
bg.pack(padx=20, pady=20)
bg.add(text="Cut", icon="scissors", command=lambda: print("Cut"))
bg.add(text="Copy", icon="copy", command=lambda: print("Copy"))
bg.add(text="Paste", icon="clipboard", command=lambda: print("Paste"))
app.mainloop()
When to use
Use ButtonGroup when:
- you have multiple actions that are conceptually related
- you want a compact toolbar cluster without separate spacing between buttons
- you want "segmented" visuals without managing per-button layout
Consider a different control when…
- you need a single/multi selection model → use ToggleGroup
- you need unrelated actions that should not look connected → use separate Button widgets
Appearance
The group style is driven by accent and variant. This sets the default for contained buttons.
See Design System → Variants for how variants map consistently across widgets.
bs.ButtonGroup(app, accent="primary").pack(pady=4)
bs.ButtonGroup(app, accent="primary", variant="outline").pack(pady=4)
bs.ButtonGroup(app, accent="primary", variant="ghost").pack(pady=4)
Examples & patterns
Icon-only toolbar group
bg = bs.ButtonGroup(app, accent="secondary", variant="ghost")
bg.pack(pady=10)
bg.add(icon="undo", icon_only=True, command=lambda: print("Undo"))
bg.add(icon="redo", icon_only=True, command=lambda: print("Redo"))
bg.add(icon="trash", icon_only=True, command=lambda: print("Delete"))
See Icons & Imagery for icon sizing, DPI handling, and recoloring behavior.
Disabling a group
You can disable individual buttons, or set the group state so all children inherit it.
bg = bs.ButtonGroup(app, accent="primary", state="disabled")
bg.pack(pady=10)
bg.add(text="Disabled", command=lambda: ...)
See State & Interaction for focus, hover, and disabled behavior across widgets.