Documentation‎ > ‎Buttons‎ > ‎

gnocl::toggleButton

A widget which switches between two states when clicked.

Synopsis

gnocl::toggleButton[-option value...]

Screenshot


Options

-active boolean
Whether the widget is active.
-activeBackgroundColor color
Background colour.
-data string
User defined data which can be retrieved via the cget subcommand.
-hasFocus 1
This sets the focus to the widget. To unset the focus it must be set to another widget.
-heightGroup string (default: "")
The -heightGroup option can be an arbitrary string. All widgets with the same heightGroup request the same height. If packed with the fill flag set, they will have nevertheless different heights.
-icon percent-string (default: "")
Image to be shown, can be either a file (prefix "%/") or a stock item (prefix "%#").
-name string
Name of the widget, can be used to set options in an rc file.
-normalBackgroundColor     color
Background colour.
-onToggled string (default: "")
Tcl script which is executed if the button is clicked.  Before evaluation the following percent strings are substituted:

%w    widget
%v    value

-onPopupMenu string (default: "")

Tcl script which is executed if the "popup-menu" signal is received, which is normally the case if the user presses Shift-F10. Before evaluation the following percent strings are substituted:

%w    widget name

-onRealize string (default: "")

Tcl script which is executed in the global scope if the widget has been realized. Before evaluation the following percent strings are substituted:

%w    widget name

-onShowHelp string (default: "")

Tcl script which is executed in the global scope if the "show-help" signal is received, which is normally the case if the user presses F1 or Ctrl-F1. Before evaluation the following percent strings are substituted:

%w    widget name
%h    help type: either "whatsThis" or "tooltip

-prelightBackgroundColor color

Background colour.
-relief ONE OF normal, half or none (default: normal)
Relief of the button.
-sensitive boolean (default: 1)
Whether or not the item is sensitive to user input.
-sizeGroup string (default: "")
The -sizeGroup option can be an arbitrary string. All widgets with the same sizeGroup request the same size. If packed with the fill flag set, they will have nevertheless different sizes.
-text percent-string (default: "")
Text or stock item of the button.
-tooltip string
Message that appear next to this widget when the mouse pointer is held over it for a short amount of time.
-visible boolean (default: 1)
Whether or not the item is visible.
-widthGroup string (default: "")
The -widthGroup option can be an arbitrary string. All widgets with the same widthGroup request the same width. If packed with the fill flag set, they will have nevertheless different widths.

Description

A button widget executes a command on mouse click.

Commands

id cget option
Returns the value for one option. The option may have any of the values accepted by configure.
id configure [-option value...]
Configures the widget. Option may have any of the values accepted on creation of the widget.
id class
Returns the class of the widget, i.e. toggleButton.
id delete
Deletes the widget and the associated Tcl command.
id onToggled
Executes the Tcl script associated with the button if there is one. This command is ignored if the button's state is not sensitive.

Example

proc update {val bar} {
    upvar $val snap
    $bar push "SNAP: $snap(x) $snap(y) $snap(z)"
}

array set snap {x 0 y 0 z 0}

set box [gnocl::box -orientation vertical]

set lab [gnocl::label -text Snap]

set stat [gnocl::statusBar]

update snap $stat

set but1 [gnocl::toggleButton \
    -text "X" \
    -variable snap(x) \
    -onValue 1 \
    -activeBackgroundColor red \
    -onToggled {update snap $stat} ]]

set but2 [gnocl::toggleButton \
    -text "Y" \
    -variable snap(y) \
    -onValue 1 \
    -activeBackgroundColor green \
    -onToggled {update snap $stat} ]]

set but3 [gnocl::toggleButton \
    -text "Z" \
    -variable snap(z) \
    -onValue 1 \
    -activeBackgroundColor blue /
    -onToggled {update snap $stat} ]]

$box add [list $lab $but1 $but2 $but3 $stat]

gnocl::window \
    -title "toggleButton" \
    -child $box

gnocl::mainLoop


Comments