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.
35 lines
990 B
Python
35 lines
990 B
Python
from textual.app import App, ComposeResult
|
|
from textual.containers import Horizontal
|
|
from textual.widgets import Switch, Static
|
|
|
|
|
|
class SwitchApp(App):
|
|
def compose(self) -> ComposeResult:
|
|
yield Static("[b]Example switches\n", classes="label")
|
|
yield Horizontal(
|
|
Static("off: ", classes="label"),
|
|
Switch(animate=False),
|
|
classes="container",
|
|
)
|
|
yield Horizontal(
|
|
Static("on: ", classes="label"),
|
|
Switch(value=True),
|
|
classes="container",
|
|
)
|
|
|
|
focused_switch = Switch()
|
|
focused_switch.focus()
|
|
yield Horizontal(
|
|
Static("focused: ", classes="label"), focused_switch, classes="container"
|
|
)
|
|
|
|
yield Horizontal(
|
|
Static("custom: ", classes="label"),
|
|
Switch(id="custom-design"),
|
|
classes="container",
|
|
)
|
|
|
|
|
|
app = SwitchApp(css_path="switch.css")
|
|
if __name__ == "__main__":
|
|
app.run()
|