tsw::toggleswitch
– Create and manipulate toggle
switch widgetstsw::toggleswitch pathName ?options?
-cursor
-command command
-offvalue value
-onvalue value
-size
1|2|3
-takefocus
0|1|""|command
-variable
variable
pathName attrib ?name
?value name value ...??
pathName cget
option
pathName configure
?option ?value option value ...??
pathName hasattrib
name
pathName identify
?element? x y
pathName instate
stateSpec ?script?
pathName state
?stateSpec?
pathName style
pathName switchstate
?boolean?
pathName toggle
pathName unsetattrib
name
tsw::toggleswitch
– Create and manipulate toggle
switch widgetstsw::toggleswitch pathName ?options?
tsw::toggleswitch
command creates a new window
named pathName
and of the class
Toggleswitch
, and makes it into a toggleswitch
widget. Additional options, described below, may be specified on the
command line or in the option database to configure aspects of the
toggleswitch widget, such as its size and the Tcl script to execute
whenever the switch state of the widget is toggled. The
tsw::toggleswitch
command returns its
pathName
argument. At the time this command is
invoked, there must not exist a window named pathName
,
but pathName
's parent must exist.-size
configuration option.space
key.switchstate
subcommand to change or query
the widget's switch state. By using the -command
configuration option, you can specify a
script to execute whenever the widget's switch state gets toggled.
For compatibility with the (ttk::)checkbutton, toggleswitch widgets also
support the -offvalue
,
-onvalue
, and -variable
options.active
,
background
, disabled
,
pressed
, and selected
) depend on
the current theme. The implementation contains procedures that create
these elements for the themes aqua
,
clam
, default
, and
vista
. The trough and slider specific to the
vista
theme are also used for the themes
winnative
and xpnative
.
Likewise, the elements specific to the default
theme
are also used for all the other themes not mentioned above (including the
third-party ones), except that in dark themes the colors of these elements
are adapted to the dark background. If the theme is
aqua
then the colors 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 preferences
changes.-cursor
Command-Line Name: | -command |
Database Name: | command |
Database Class: | Command |
Specifies a Tcl script to be evaluated at global scope whenever the switch state of the widget is toggled (programmatically or interactively). The default is an empty string.
Command-Line Name: | -offvalue |
Database Name: | offValue |
Database Class: | OffValue |
The value to store in the associated variable when the widget's switch state is set to off. Defaults to
0
.
Command-Line Name: | -onvalue |
Database Name: | onValue |
Database Class: | OnValue |
The value to store in the associated variable when the widget's switch state is set to on. Defaults to
1
.
Command-Line Name: | -size |
Database Name: | size |
Database Class: | Size |
Specifies the size identifier of the toggleswitch widget. The supported values are the strings
1
,2
, and3
. If the current theme isaqua
then the value1
stands for the trough size of 26 x 15 pixels, the value2
for the trough size of 32 x 18 pixels, and the value3
identifies the trough size of 38 x 22 pixels. For all the other themes, on an unscaled screen the value1
stands for the trough size of 32 x 16 pixels, the value2
for the trough size of 40 x 20 pixels, and the value3
identifies the trough size of 48 x 24 pixels, except that on Windows 10 and earlier, for the themesvista
,winnative
, andxpnative
the unscaled trough width is 35, 44, and 53 pixels, respectively (for compatibility with the native toggle switch). The default is2
(for all themes).
Command-Line Name: | -takefocus |
Database Name: | takeFocus |
Database Class: | TakeFocus |
This option determines whether the toggleswitch widget accepts the focus during keyboard traversal. It is almost identical to the standard option of the same name (see the options manual entry for details). The only difference is that not the toggleswitch itself but the ttk::scale widget contained in it will receive the focus during keyboard traversal with the standard keys (
Tab
andShift-Tab
). The default is"ttk::takefocus"
(just like for most Tk themed widgets).
Command-Line Name: | -variable |
Database Name: | variable |
Database Class: | Variable |
The name of a global variable whose value is linked to the toggleswitch. The widget's switch state changes to on when this variable is set to the value specified by the
-onvalue
option and to off otherwise. Defaults to the widget's pathname if not specified.
tsw::toggleswitch
command creates a new Tcl
command whose name is pathName
. This command
may be used to invoke various operations on the widget. It has the
following general form:
pathName option ?arg arg ...?
option
and the arg
s determine
the exact behavior of the command. The following commands are
possible for toggleswitch widgets:pathName attrib
?name ?value name value ...??
name
is specified, the command returns a list of
pairs, each of which contains the name and the value of an attribute
for pathName
. If name
is
specified with no value
, then the command returns
the value of the one named attribute, or an empty string if no
corresponding value exists (you can use the hasattrib
subcommand to distinguish this
case from the one that the value of an existing attribute is an
empty string). If one or more
name
-value
pairs are specified,
then the command sets the given widget attribute(s) to the given
value(s); in this case the return value is an empty string.
name
may be an arbitrary string.pathName cget
option
option
, which may have any of the values accepted
by the tsw::toggleswitch
command.pathName configure
?option ?value option value
...??
option
is specified, the command returns a
list describing all of the available options for
pathName
(see Tk_ConfigureInfo
for information on the format of this list). If
option
is specified with no
value
, then the command returns a list describing
the one named option (this list will be identical to the corresponding
sublist of the value returned if no option
is
specified). If one or more
option
-value
pairs are
specified, then the command modifies the given widget option(s) to have
the given value(s); in this case the return value is an empty
string. option
may have any of the values
accepted by the tsw::toggleswitch
command.pathName hasattrib
name
1
if the attribute name
exists and 0
otherwise.pathName identify
?element? x y
pathName instate
stateSpec ?script?
pathName state
?stateSpec?
pathName
style
Toggleswitch1
,
Toggleswitch2
, or
Toggleswitch3
, depending on the value of the
-size
option. For Tk
themed widgets this subcommand was introduced in Tk 8.7a4, but the
toggleswitch widget provides it for all supported Tk versions.pathName
switchstate ?boolean?
true/yes/on
or
false/no/off
). If it is true
then the command sets the selected
flag of the
underlying ttk::scale widget, moves the slider to the end of the
trough, and sets the associated variable to the
value specified by the -onvalue
option; otherwise it clears the
selected
flag, moves the slider to the beginning of
the trough, and sets the associated variable to the value specified by
the -offvalue
option.
If the argument's value causes the widget's switch state to get toggled
and the script specified as the value of the -command
option is a nonempty string then the
subcommand evaluates that script at global scope and returns its
result; otherwise the return value is an empty string. If the
optional argument is not present then the command returns the widget's
current switch state as 0
or 1
. When a
toggleswitch widget is created, its switch state is initialized with
0
.pathName
toggle
if {[pathName switchstate]} { return [pathName switchstate 0] } else { return [pathName switchstate 1] }
pathName
unsetattrib name
name
. Returns an
empty string.aqua
:
space
key causes its switch state to get toggled.aqua
:
0
or 1
,
depending on the slider's position relative to the middle of the
widget.space
key causes its switch state to get toggled.disabled
state flag is
set then none of the above actions occur.