mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
A new form of Checkbox will be arriving in Textual soon, working in conjunction with a RadioButton. What was called Checkbox is perhaps a wee bit heavyweight in terms of visual design, but is a style of widget that should remain. With this in mind we're renaming the current Checkbox to Switch. In all other respects its workings remains the same, only the name has changed. Things for people to watch out for: - Imports will need to be updated. - Queries will need to be updated; special attention will need to be paid to any queries that are string-based. - CSS will need to be changed if any Checkbox styling is happening, or if any Checkbox component styles are being used. See #1725 as the initial motivation and #1746 as the issue for this particular change.
1.2 KiB
1.2 KiB
Switch
A simple switch widget which stores a boolean value.
- Focusable
- Container
Example
The example below shows switches in various states.
=== "Output"
```{.textual path="docs/examples/widgets/switch.py"}
```
=== "switch.py"
```python
--8<-- "docs/examples/widgets/switch.py"
```
=== "switch.css"
```sass
--8<-- "docs/examples/widgets/switch.css"
```
Reactive Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value |
bool |
False |
The default value of the switch. |
Bindings
The switch widget defines directly the following bindings:
::: textual.widgets.Switch.BINDINGS options: show_root_heading: false show_root_toc_entry: false
Component Classes
The switch widget provides the following component classes:
::: textual.widgets.Switch.COMPONENT_CLASSES options: show_root_heading: false show_root_toc_entry: false
Messages
::: textual.widgets.Switch.Changed
Additional Notes
- To remove the spacing around a
Switch, setborder: none;andpadding: 0;.
See Also
- Switch code reference