Just like a light switch, a toggleswitch widget can have one of two possible switch states: on or off. In the on state the slider is placed at the end of the trough, and in the off state at its beginning. The user can toggle between these two states with the mouse or the space key.
The colors used when drawing the trough and slider in the various widget states depend on the current theme. If the theme is aqua then they also depend on the system appearance (light mode or dark mode) and the accent color, and are automatically adapted whenever one of these global system settings changes.
The implementation creates these elements when needed with the aid of generic code for arbitrary themes and theme-specific one for a few built-in themes. Applications can add explicit support for any theme theme by providing an appropriate command of the name ttk::toggleswitch::CreateElements_theme.
Note that by setting this option to a value size, the -style option's value will automatically change to Toggleswitchsize or ToggleswitchExsize if its previous or requested value was one of Toggleswitch1, Toggleswitch2, Toggleswitch3, ToggleswitchEx1, ToggleswitchEx2, or ToggleswitchEx3. Similarly, the value of the -style option will automatically change to prefix.Toggleswitchsize or prefix.ToggleswitchExsize if its previous or requested value was one of prefix.Toggleswitch1, prefix.Toggleswitch2, prefix.Toggleswitch3, prefix.ToggleswitchEx1, prefix.ToggleswitchEx2, or prefix.ToggleswitchEx3.
Conversely, by setting the -style option to a value of one of the forms Toggleswitchsize, ToggleswitchExsize, prefix.Toggleswitchsize, or prefix.ToggleswitchExsize (where size is one of 1, 2, or 3), the -size option will automatically be set to size.
When configuring both options -size and -style, the former will take precedence over the latter, regardless of the order in which they were specified. For example, if you create the widget with
ttk::toggleswitch pathName -size 3 -style My.Toggleswitch3
or invoke
pathName configure -style My.Toggleswitch3
then the -style option will be set to My.Toggleswitch3 (and the -size option will have the value 3). On the other hand, if you create the widget with
ttk::toggleswitch pathName -style My.Toggleswitch3
then the -style option will have the value My.Toggleswitch2 rather than My.Toggleswitch3, because the widget creation triggers the default -size 2 setting, which takes precedence over -style My.Toggleswitch3.
Note that, just like in the case of the (ttk::)checkbutton, toggling the widget's switch state by changing the value of this variable will not cause the script specified by the -command option to get executed.
If the current theme is aqua:
If the current theme is different from aqua:
If the widget's disabled state flag is set then none of the above actions occur.
Dynamic states: active, background, disabled, invalid, pressed, selected.
Styling options configurable with ttk::style for Toggleswitch1, Toggleswitch2, Toggleswitch3, ToggleswitchEx1, ToggleswitchEx2, and ToggleswitchEx3:
-background color
-focuscolor color
For the aqua theme the focus-related options are simply ignored.
See the ttk_style manual page for information on how to configure ttk styles.