simvx.core.ui.button_group

ButtonGroup: keeps at most one of a set of toggle buttons checked.

Module Contents

Classes

ButtonGroup

Makes its buttons mutually exclusive: checking one unchecks the rest.

Data

API

simvx.core.ui.button_group.__all__

[‘ButtonGroup’]

class simvx.core.ui.button_group.ButtonGroup(*, allow_unchecked: bool = False)[source]

Makes its buttons mutually exclusive: checking one unchecks the rest.

The toggle state lives on each button (Button.checked); the group only enforces exclusivity, so a button joins with Button(group=grp) or button.group = grp and leaves with button.group = None. A button in a group is a toggle button: joining sets its toggle_mode.

The group is a plain object, not a node, so its buttons can sit anywhere in the tree, in different containers or different panels.

allow_unchecked decides what a click on the checked member does: by default it holds, so one member stays checked once the player has chosen, the way radio buttons behave; with allow_unchecked=True the click unchecks it and the group is left with none checked, which suits a tool palette where “no tool” is a valid choice. A RadioButton holds either way.

checked_changed(button) fires when the player’s click changes which member is checked, with the new one or None. Setting checked from code keeps the group exclusive and fires nothing, as every widget’s own signals do.

Example: tools = ButtonGroup() for name in (“Brush”, “Eraser”, “Fill”): bar.add_child(Button(name, group=tools)) tools.checked_changed.connect(lambda b: print(“tool:”, b.text if b else None))

Initialization

property buttons: tuple[simvx.core.ui.widgets.Button, ...][source]

The member buttons, in the order they joined.

property checked_button: simvx.core.ui.widgets.Button | None[source]

The checked member, or None when none is.

__repr__() → str[source]