hwtk::checkbutton

On/off widget

Format

hwtk::checkbutton - pathName ?option value? …

Description

A hwtk::checkbutton widget is used to show or change a setting. It has two states, selected and deselected. The state of the checkbutton may be linked to a Tcl variable.

Standard Options

-clientdata
Database name: clientData
Database class: ClientData
Acts as a data storage for a widgets. User can store any data and this will not have any effect on widget property.
-compound
Database name: compound
Database class: Compound
Specifies if the widget should display text and bitmaps/images at the same time, and if so, where the bitmap/image should be placed relative to the text. Must be one of the values none, bottom, top, left, right, or center. For example, the (default) value none specifies that the bitmap or image should (if defined) be displayed instead of the text, the value left specifies that the bitmap or image should be displayed to the left of the text, and the value center specifies that the bitmap or image should be displayed on top of the text.
-cursor
Database name: cursor
Database class: Cursor
Specifies the mouse cursor to be used for the widget. See Tk_GetCursor and cursors(n) in the Tk reference manual for the legal values. If set to the empty string (the default), the cursor is inherited from the parent widget.
-help
Database name: help
Database class: Text
Specifies the text or help message that displays when the cursor moves over the widget.
-helpcommand
Database name: helpcommand
Database class: Command
Dynamic help which calls an assigned -helpcommand when the user moves the mouse on the widget. The text which is returned by the -helpcommand will be in turn be displayed on the tooltip.
-image
Database name: image
Database class: Image
Specifies an image to display in the widget, which must have been created with the image create command. Typically, if the image option is specified then it overrides other options that specify a bitmap or textual value to display in the widget, though this is controlled by the compound option; the image option may be reset to an empty string to re-enable a bitmap or text display.
-state
Database name: state
Database class: State
May be set to normal or disabled to control the disabled state bit.
-takefocus
Database name: takeFocus
Database class: TakeFocus
Determines whether the window accepts the focus during keyboard traversal. Either 0, 1, a command prefix (to which the widget path is appended, and which should return 0 or 1), or the empty string. See options(n) in the Tk reference manual for the full description.
-text
Database name: text
Database class: Text
Specifies a string to be displayed inside the widget. The way in which the string is displayed depends on the particular widget and may be determined by other options, such as anchor or justify.
-textvariable
Database name: textVariable
Database class: Variable
Specifies the name of a global variable. The value of the variable is a text string to be displayed inside the widget; if the variable value changes then the widget will automatically update itself to reflect the new value. The way in which the string is displayed in the widget depends on the particular widget and may be determined by other options, such as anchor or justify.
-underline
Database name: underline
Database class: Underline
Specifies the integer index of a character to underline in the widget. This option is used by the default bindings to implement keyboard traversal for menu buttons and menu entries. 0 corresponds to the first character of the text displayed in the widget, 1 to the next character, and so on.
-width
Database name: width
Database class: Width
Specifies the width of a widget.

Widget-Specific Options

-command
Database name: command
Database class: Command
A script to evaluate when the widget is invoked.
-offvalue
Database name: offValue
Database class: OffValue
The value to store in the associated -variable when the widget is deselected. Defaults to 0.
-onvalue
Database name: onValue
Database class: OnValue
The value to store in the associated -variable when the widget is selected. Defaults to 0.
-variable
Database name: variable
Database class: Variable
The name of a global variable whose value is linked to the widget. Defaults to the widget pathname if not specified.

Widget Command

pathName configure ?option? ?value option value …?
Query or modify the configuration options of the widget. 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. If option is specified with no value, then the command returns a list describing the named option: the elements of the list are the option name, database name, database class, default value, and current value. If no option is specified, returns a list describing all of the available options for pathName.
pathName cget option
Returns the current value of the configuration option given by option.
pathName identify element x y
Returns the name of the element under the point given by x and y, or an empty string if the point does not lie within any element. x and y are pixel coordinates relative to the widget. Some widgets accept other identify subcommands.
pathName instate statespec ?script?
Test the widget’s state. If script is not specified, returns 1 if the widget state matches statespec and 0 otherwise. If script is specified, equivalent to
if{[pathNameinstatestateSpec]}script
pathName state ?stateSpec?
Modify or inquire widget state. If stateSpec is present, sets the widget state: for each flag in stateSpec, sets the corresponding flag or clears it if prefixed by an exclamation point. Returns a new state spec indicating which flags were changed:
setchanges[pathNamestatespec]
pathNamestate$changes
will restore pathName to the original state. If stateSpec is not specified, returns a list of the currently-enabled state flags.
pathName invoke
Toggles between the selected and deselected states and evaluates the associated -command. If the widget is currently selected, sets the -variable to the -offvalue and deselects the widget; otherwise, sets the -variable to the -onvalue. Returns the result of the -command.

Example

::hwtk::dialog .d -title "::hwtk::checkbutton"
set f [.d recess]

array set state {wipers 1 brakes 0 driver 1 }

hwtk::checkbutton $f.ck1 -text "Wipers OK" -help "Select safety item - wipers" -variable state(wipers)
hwtk::checkbutton $f.ck2 -text "Brakes OK" -help "Select safety item - brakes" -variable state(brakes)
hwtk::checkbutton $f.ck3 -text "Drive sober" -help "Select safety item - driver state" -variable state(driver)

grid $f.ck1 -sticky w
grid $f.ck2 -sticky w
grid $f.ck3 -sticky w

.d post