Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
A checkbox-type control styled as a colored toggle slider
ResourceFunction["OnOffToggle"][Dynamic[arg]] represents a toggle switch with setting arg. | |
ResourceFunction["OnOffToggle"][Dynamic[arg,fn]] represents a toggle switch with setting arg and update function fn. |
| "Interaction" | "Click" | whether mouse click or mouse drag actions are required |
| "OffBackgroundColor" | LightGray | background color when False |
| "OffColor" | Lighter[Red,0.2] | toggle color when False |
| "OnBackgroundColor" | LightGray | background color when True |
| "OnColor" | Lighter[Green] | toggle color when True |
| FrameStyle | None | style appled to the toggler frame |
| ImageSize | 40 | horizontal size of the toggler |
Create an interactive switch that can be toggled with a mouse click:
| In[1]:= |
| Out[2]= |
When the control variable is True, the switch moves to the right and changes color:
| In[3]:= |
| Out[4]= |
Two-argument Dynamic is supported:
| In[5]:= |
| Out[6]= |
The toggle color and background color can be individually controlled for both the on and off states:
| In[8]:= | ![]() |
| Out[9]= |
| In[10]:= | ![]() |
| Out[11]= |
A frame can also be styled:
| In[12]:= |
| Out[12]= |
The controller size can be set with ImageSize:
| In[13]:= |
| Out[13]= | ![]() |
The controller switches state with mouse clicks, but it can be set to require dragging between states. Any position right of center is treated as True:
| In[14]:= |
| Out[14]= |
This work is licensed under a Creative Commons Attribution 4.0 International License