The toggleswitch Widget

by

Trevor Williams

phase1geo@gmail.com

Reference

NAME
toggleswitch::toggleswitch - Create and manipulate toggleswitch widgets

SYNOPSIS
toggleswitch::toggleswitch pathName ?options?
STANDARD OPTIONS
-borderwidth
-cursor
-font
-relief
-state
-takefocus
-variable
WIDGET-SPECIFIC OPTIONS
-command name
-offbackground color
-offforeground color
-offvalue variable
-onbackground color
-onforeground color
-onvalue variable
DESCRIPTION

WIDGET COMMANDS

pathName cget option
pathName configure ?option? ?value option value ...?
pathName invoke
pathName switchoff
pathName switchon
pathName toggle

DEFAULT BINDINGS

KEYWORDS

Detailed Reference

NAME
toggleswitch::toggleswitch - Create and manipulate toggleswitch widgets

SYNOPSIS
toggleswitch::toggleswitch pathName ?options?
STANDARD_OPTIONS
-borderwidth
-cursor
-font
-relief
-state
-takefocus
-variable
See the options manual entry for details on the standard options.

WIDGET-SPECIFIC OPTIONS

Command-Line Name:  -command
Database Name:  command
Database Class:  Command

A Tcl script to execute whenever the widget is invoked. The widget's global variable (-variable option) will be updated before the command is invoked.

Command-Line Name:  -offbackground
Database Name:  offBackground
Database Class:  Background

Specifies the background color to use for the off side of the widget.

Command-Line Name:  -offforeground
Database Name:  offForeground
Database Class:  Foreground

Specifies the foreground color to use for the off side of the widget.

Command-Line Name:  -offvalue
Database Name:  offValue
Database Class:  Value

Specifies value to store in the widget's associated variable whenever this widget is set to the off position. Defaults to "0".

Command-Line Name:  -onbackground
Database Name:  onBackground
Database Class:  Background

Specifies the background color to use for the on side of the widget.

Command-Line Name:  -onforeground
Database Name:  onForeground
Database Class:  Foreground

Specifies the foreground color to use for the on side of the widget.

Command-Line Name:  -onvalue
Database Name:  onValue
Database Class:  Value

Specifies value to store in the widget's associated variable whenever this widget is set to the on position. Defaults to "1".

DESCRIPTION

The toggleswitch::toggleswitch command creates a new window named pathName and of the class ToggleSwitch, and makes it into a toggleswitch widget.  Additional options, described above, may be specified on the command-line or in the option database to configure aspects of the toggleswitch.  The toggleswitch::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.

The toggleswitch widget is a widget that looks like an on/off switch. The widget acts like a checkbutton widget in all other aspects. The user can switch the widget to the on/off state by either left-clicking on the on/off sides of the widget or by sliding the slider to either side.

WIDGET COMMANDS

The toggleswitch::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 determine the exact behavior of the command.  The following commands are possible for tokenentry widgets:

pathName cget option
Returns the current value of the configuration option given by option. Option may have any of the values accepted by the Tk entry command.

pathName configure ?option? ?value option value ...?
Query or modify the configuration options of the widget. If no option is specified, 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 command returns an empty string. Option may have any of the values accepted by the Tk entry command.

pathName invoke
Does just what would have happend if the user invoked the toggleswitch with the mouse: toggle the on/off state of the widget and invoke the Tcl command associated with the toggleswitch, if there is one. The return value is the return value from the Tcl command, or an empty string if there is no command associated with the toggleswitch. This command is ignored if the toggleswitch's state is disabled.

pathName switchoff
Switches the widget to the "off" position and sets the associated variable to its "off" value.

pathName switchon
Switches the widget to the "on" position and sets the associated variable to its "on" value.

pathName toggle
Toggles the on/off value of the widget, redisplaying it and modifying its associated variable to reflect the new state.
DEFAULT BINDINGS

Tk automatically creates class bindings for entries that give them the following default behavior. In the descriptions below, "word" refers to a contiguous group of letters, digits, or "_" characters, or any single character other than these.
  1. Clicking mouse button 1 on the "ON" text will slide the slider to the left, switching the value of the toggleswitch to the "off" value, revealing the "OFF" text.

  2. Clicking mouse button 1 on the "OFF" text will slide the slider to the right, switching the value of the toggleswitch to the "on" value, revealing the "ON" text.

  3. Pressing mouse button 1 on the switch slider and moving the mouse with mouse button 1 pressed will move the toggleswitch slider under the mouse position. Releasing mouse button 1 will move the slider to the on or off position depending on the position of the slider's midpoint.

  4. Pressing the space bar while the widget has focus will toggle the value of the toggleswitch.

  5. When the toggleswitch loses focus, the focus is given to the next item that has its -takefocus value set to a value of 1.
KEYWORDS

checkbutton, widget