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.
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
|
press_on_selection
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
KeyBindError
|
If any key in b_keys is not a single ASCII alphanumeric character. |
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 |