MCPcopy Index your code
hub / github.com/Textualize/textual / ToggleButton

Class ToggleButton

src/textual/widgets/_toggle_button.py:25–285  ·  view source on GitHub ↗

Base toggle button widget. Warning: `ToggleButton` should be considered to be an internal class; it exists to serve as the common core of [Checkbox][textual.widgets.Checkbox] and [RadioButton][textual.widgets.RadioButton].

Source from the content-addressed store, hash-verified

23
24
25class ToggleButton(Static, can_focus=True):
26 """Base toggle button widget.
27
28 Warning:
29 `ToggleButton` should be considered to be an internal class; it
30 exists to serve as the common core of [Checkbox][textual.widgets.Checkbox] and
31 [RadioButton][textual.widgets.RadioButton].
32 """
33
34 ALLOW_SELECT = False
35 BINDINGS: ClassVar[list[BindingType]] = [
36 Binding("enter,space", "toggle_button", "Toggle", show=False),
37 ]
38 """
39 | Key(s) | Description |
40 | :- | :- |
41 | enter, space | Toggle the value. |
42 """
43
44 COMPONENT_CLASSES: ClassVar[set[str]] = {
45 "toggle--button",
46 "toggle--label",
47 }
48 """
49 | Class | Description |
50 | :- | :- |
51 | `toggle--button` | Targets the toggle button itself. |
52 | `toggle--label` | Targets the text label of the toggle button. |
53 """
54
55 DEFAULT_CSS = """
56 ToggleButton {
57 width: auto;
58 border: tall $border-blurred;
59 padding: 0 1;
60 background: $surface;
61 text-wrap: nowrap;
62 text-overflow: ellipsis;
63 pointer: pointer;
64
65 &:ansi {
66 background: ansi_default;
67 & > .toggle--button {
68 background: $ansi-background;
69 color: $ansi-foreground;
70 text-style: dim;
71 }
72 &.-on > .toggle--button {
73 color: $accent;
74 background: $ansi-background;
75 text-style: bold not dim;
76 }
77 }
78
79 &.-textual-compact {
80 border: none !important;
81 padding: 0;
82 &:focus {

Callers 1

composeMethod · 0.90

Calls 2

BindingClass · 0.90
reactiveClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…