Skip to content

Button & ButtonKeyBind

Button

A single selectable item. Provide a label (displayed text) and a value (returned when the button is confirmed). Optionally attach a ButtonKeyBind and a per-button ButtonStyle override.

Button

A selectable button with an optional key binding and custom style.

label property

label: str

Display label of the button.

value property

value: Any

Value returned when the button is confirmed.

local_button_style property

local_button_style: ButtonStyle | None

Per-button style override, or None to use the component's global style.


ButtonKeyBind

Keyboard shortcut configuration for a single Button.

ButtonKeyBind dataclass

Key binding configuration for a Button.

Parameters:

Name Type Description Default
b_keys list[str]

Single ASCII alphanumeric characters that trigger the button.

required
case_sensitive bool

Whether matching is case-sensitive. Defaults to False.

False
press_on_selection bool

If True, selecting via key immediately confirms the button. Defaults to False.

False

Raises:

Type Description
KeyBindError

If any key in b_keys is not a single ASCII alphanumeric character.

b_keys instance-attribute

b_keys: list[str]

case_sensitive class-attribute instance-attribute

case_sensitive: bool = False

press_on_selection class-attribute instance-attribute

press_on_selection: bool = False

Quick reference

from interactive_buttons import Button, ButtonKeyBind

# Bind keys "y" and "Y"; instant-confirm on press
yes_bind = ButtonKeyBind(
    b_keys=["y"],
    press_on_selection=True,   # confirm without pressing Enter
    case_sensitive=False,      # y and Y both match (default)
)

btn = Button(
    label="Yes",
    value=True,
    key_bind=yes_bind,
)
Rule Detail
b_keys entries Single ASCII alphanumeric characters only (A-Z, a-z, 0-9)
Duplicate keys Not allowed across buttons in the same Component
display_index Cannot be combined with key_bind