Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
A button that cycles through a list of titles and actions when clicked
| ResourceFunction["ToggleButton"][{label1⧴ action1,label2⧴ action2,…}] represents a cyclically toggling button that executes actioni when the title labeli is pressed. | 
Create a button that cycles though values:
| In[1]:= | ![ResourceFunction["ToggleButton"][Thread[Range@3 :> Null]]](https://www.wolframcloud.com/obj/resourcesystem/images/59a/59ac650c-e718-4bee-b953-133e6a7b5ea7/5e7afa58c53d3032.png) | 
| Out[1]= |  | 
Create a button that switches between two actions:
| In[2]:= | ![ResourceFunction[
 "ToggleButton"][{"a" :> Print["a"], "b" :> Print["b"]}]](https://www.wolframcloud.com/obj/resourcesystem/images/59a/59ac650c-e718-4bee-b953-133e6a7b5ea7/15f8f76eab97cbab.png) | 
| Out[2]= |  | 



Use any of the standard Button options:
| In[3]:= | ![Column @ Table[
  ResourceFunction[
   "ToggleButton"][{"A" :> Null, "B" :> Null, "C" :> Null}, Appearance -> a], {a, {"DialogBox", {"DialogBox", "Pressed"}, "Palette", {"Palette", "Pressed"}}}]](https://www.wolframcloud.com/obj/resourcesystem/images/59a/59ac650c-e718-4bee-b953-133e6a7b5ea7/1af8422f254b8052.png) | 
| Out[3]= |  | 
Style your ToggleButton like a normal Button:
| In[4]:= | ![ResourceFunction[
 "ToggleButton"][{"Pause 0.1s" :> Pause@.1, "Pause 1s" :> Pause@1},
 Background -> LightBlue, ImageSize -> {150, 50}, BaseStyle -> {"GenericButton", 16, Bold, Darker@Green}]](https://www.wolframcloud.com/obj/resourcesystem/images/59a/59ac650c-e718-4bee-b953-133e6a7b5ea7/30a3b73868f64d27.png) | 
| Out[4]= |  | 
Create a play/pause button:
| In[5]:= | ![a = ExampleData[{"Audio", "CelloScale"}];
astream = AudioStream[a];
Row@{ResourceFunction["ToggleButton"][{"\!\(\*
StyleBox[\"\[RightPointer]\",\nFontSize->18]\)" :> AudioPlay@astream, "Ⅱ" :> AudioPause@astream}], Dynamic[astream["Position"]]}](https://www.wolframcloud.com/obj/resourcesystem/images/59a/59ac650c-e718-4bee-b953-133e6a7b5ea7/506ba6e873c79a73.png) | 
| Out[7]= |  | 
Create a button that toggles cycles through some images:
| In[8]:= | ![DynamicModule[{$img = Text["Nothing loaded"], btn},
 btn = ResourceFunction["ToggleButton"][{
    "Load \!\(\*
StyleBox[\"Glasses\",\nFontSlant->\"Italic\"]\)" :> ($img = Import@"ExampleData/glasses.png"),
    "Load \!\(\*
StyleBox[\"Turtle\",\nFontSlant->\"Italic\"]\)" :> ($img = Import@"ExampleData/turtle.jpg"),
    "Load \!\(\*
StyleBox[\"Spikey\",\nFontSlant->\"Italic\"]\)" :> ($img = Import@"ExampleData/spikey2.png")
    }];
 Panel@Labeled[Dynamic[$img], btn, Top]
 ]](https://www.wolframcloud.com/obj/resourcesystem/images/59a/59ac650c-e718-4bee-b953-133e6a7b5ea7/1be20b920fedc0f3.png) | 
| Out[8]= |  | 
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License