Getting Started¶
Installation¶
The library requires Python 3.10+ and two lightweight dependencies:
| Package | Purpose |
|---|---|
colorama |
Cross-platform ANSI color codes |
readchar |
Raw single-keystroke input |
Your first button menu¶
1. Import the building blocks¶
2. Create your buttons¶
Each Button has a label (what the user sees) and a value (what your code receives).
buttons = [
Button(label="Start game", value="start"),
Button(label="Load save", value="load"),
Button(label="Settings", value="settings"),
Button(label="Quit", value="quit"),
]
3. Wrap them in a Component¶
Component is the renderer and input handler. Pass a style preset or your own ButtonStyle.
4. Display and wait for a selection¶
Pick a layout : column_buttons, linear_buttons, or matrix_buttons, and call it. The call blocks until the user confirms a choice and returns that button's value.
Component options at a glance¶
| Parameter | Type | Default | Description |
|---|---|---|---|
buttons |
list[Button] | - | Ordered list of buttons |
global_buttons_style |
ButtonStyle |
DEFAULT_STYLE |
Style applied to buttons without a local override |
display_index |
bool |
False |
Auto-prefix each button with a digit shortcut (1, 2, ...) |
index_begin |
int |
1 |
Starting digit when display_index is active |
auto_erase |
bool |
False |
Erase the rendered buttons automatically after selection |
Navigation keys¶
| Layout | Keys |
|---|---|
column_buttons |
up / down * Enter |
linear_buttons |
left / right * Enter |
matrix_buttons |
left / right / up / down * Enter |
In all layouts, digit shortcuts (when display_index=True) or custom key bindings jump directly to a button.
What's next?¶
-
Layout examples
See all three layouts with full working code.
-
Style customisation
Browse presets or build your own
ButtonStyle. -
Key bindings
Assign hotkeys, control case sensitivity, and use instant-confirm.