RadioButton¶
Added in version 0.13.0
A simple radio button which stores a boolean value.
- Focusable
- Container
A radio button is best used with others inside a RadioSet
.
Example¶
The example below shows radio buttons, used within a RadioSet
.
from textual.app import App, ComposeResult
from textual.widgets import RadioButton, RadioSet
class RadioChoicesApp(App[None]):
CSS_PATH = "radio_button.tcss"
def compose(self) -> ComposeResult:
with RadioSet():
yield RadioButton("Battlestar Galactica")
yield RadioButton("Dune 1984")
yield RadioButton("Dune 2021", id="focus_me")
yield RadioButton("Serenity", value=True)
yield RadioButton("Star Trek: The Motion Picture")
yield RadioButton("Star Wars: A New Hope")
yield RadioButton("The Last Starfighter")
yield RadioButton(
"Total Recall :backhand_index_pointing_right: :red_circle:"
)
yield RadioButton("Wing Commander")
def on_mount(self) -> None:
self.query_one(RadioSet).focus()
if __name__ == "__main__":
RadioChoicesApp().run()
Reactive Attributes¶
Name | Type | Default | Description |
---|---|---|---|
value |
bool |
False |
The value of the radio button. |
Messages¶
Bindings¶
The radio button widget defines the following bindings:
Key(s) | Description |
---|---|
enter, space | Toggle the value. |
Component Classes¶
The checkbox widget inherits the following component classes:
Class | Description |
---|---|
toggle--button |
Targets the toggle button itself. |
toggle--label |
Targets the text label of the toggle button. |
See Also¶
Bases: ToggleButton
A radio button widget that represents a boolean value.
Note
A RadioButton
is best used within a RadioSet.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
TextType
|
The label for the toggle. |
''
|
|
bool
|
The initial value of the toggle. |
False
|
|
bool
|
Should the button come before the label, or after? |
True
|
|
str | None
|
The name of the toggle. |
None
|
|
str | None
|
The ID of the toggle in the DOM. |
None
|
|
str | None
|
The CSS classes of the toggle. |
None
|
|
bool
|
Whether the button is disabled or not. |
False
|
|
RenderableType | None
|
RenderableType | None = None, |
None
|
BUTTON_INNER
class-attribute
instance-attribute
¶
The character used for the inside of the button.
Changed
¶
Changed(toggle_button, value)
Bases: Changed
Posted when the value of the radio button changes.
This message can be handled using an on_radio_button_changed
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
ToggleButton
|
The toggle button sending the message. |
required |
|
bool
|
The value of the toggle button. |
required |