toggle
pdwidgets.widgets.toggle
Icon toggle base class.
Toggle(parent, x=0, y=0, w=None, h=None, align=None, align_to=None, fg=None, bg=None, visible=True, value=False, padding=None, on_file=None, off_file=None)
Bases: IconButton
Icon button that toggles between on and off states.
An IconButton that toggles between two states (on and off). Serves as a base widget for ToggleButton, CheckBox, and RadioButton widgets but may be used on its own. Requires an on_file and optionally an off_file. If only a single file is provided, the widget will change colors when toggled, otherwise the icon will change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Widget
|
The parent widget or screen that contains this toggle button. |
required |
x
|
int
|
The x-coordinate of the toggle button. |
0
|
y
|
int
|
The y-coordinate of the toggle button. |
0
|
w
|
int
|
The width of the toggle button. |
None
|
h
|
int
|
The height of the toggle button. |
None
|
align
|
int
|
The alignment of the toggle button. |
None
|
align_to
|
Widget
|
The widget to align to. |
None
|
fg
|
int
|
The color of the toggle button. |
None
|
bg
|
int
|
The background color of the toggle button. |
None
|
visible
|
bool
|
The visibility of the toggle button. |
True
|
value
|
bool
|
The initial state of the toggle button. |
False
|
padding
|
tuple
|
The padding on each side of the toggle button. |
None
|
on_file
|
str
|
The icon file to display when the button is on. |
None
|
off_file
|
str
|
The icon file to display when the button is off. |
None
|
Usage
toggle = Toggle(screen, on_file="on.pbm", off_file="off.pbm")
changed()
Update the icon based on the current on/off state.
toggle(data=None, event=None)
Toggle the on/off state of the button.