simvx.core.ui.button_group¶
ButtonGroup: keeps at most one of a set of toggle buttons checked.
Module Contents¶
Classes¶
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 withButton(group=grp)orbutton.group = grpand leaves withbutton.group = None. A button in a group is a toggle button: joining sets itstoggle_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_uncheckeddecides 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; withallow_unchecked=Truethe click unchecks it and the group is left with none checked, which suits a tool palette where “no tool” is a valid choice. ARadioButtonholds either way.checked_changed(button)fires when the player’s click changes which member is checked, with the new one orNone. Settingcheckedfrom 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
Nonewhen none is.