[Chapter 18] 18.5 The Checkbutton Widget
Author: Ellen Siever, Stephen Spainhour & Nathan Patwardhan
Date: 1999-07-02T01:58:51Z

#

| Chapter 18 Perl/Tk |

## 18.5 The Checkbutton Widget

Creates a checkbutton with the `Checkbutton` command. A checkbutton has an indicator to the left of the label indicating whether the button is selected. The boolean status of the button ("0" or "1", or values as specified by the `-onvalue` and `-offvalue` options) is stored in the variable specified with the `-variable` option.

>     $parentwidget->Checkbutton (options)

The standard configuration options that apply to `CheckButton` are: `-activebackground`, `-activeforeground`, `-anchor`, `-background`, `-bg`, `-bitmap`, `-borderwidth`, `-bd`, `-cursor`, `-disabledforeground`, `-font`, `-foreground`, `-fg`, `-height`, `-highlightbackground`, `-highlightcolor`, `-highlightthickness`, `-image`, `-justify`, `-padx`, `-pady`, `-relief`, `-state`, `-takefocus`, `-underline`, `-width`, and `-wraplength`.

Other options are:

`-command =>` `callback`

  Pointer to a function that will be called when the checkbutton is pressed.

`-indicatoron =>` `boolean`

  Determines whether or not to display the indicator. Default is on (1).

`-offvalue =>` `newvalue`

  Specifies the value used when the checkbutton is "off." Must be a scalar. Default is 0.

`-onvalue =>` `newvalue`

  Specifies the value used when the checkbutton is "on." Must be a scalar. Default is 1.

`-selectcolor =>` `color`

  Color of the indicator when the checkbutton is "on."

`-selectimage =>` `imgptr`

  Defines the image to be displayed instead of text when the checkbutton is "on." Ignored if `-image` is not used.

`-text =>` '`text`'

  Defines the text string displayed in the checkbutton. See also `-textvariable`.

`-textvariable =>` `\$variable`

  Points to the variable containing text to be displayed in the checkbutton. Button text will change as `$variable` does.

`-variable =>` `\$variable`

  Associates the on/off value of the indicator with the specified variable.

### 18.5.1 Checkbutton Methods

In addition to `configure` and `cget`, the following methods are supported by Checkbutton:

`deselect`

  Sets the indicator to the "off" state.

`select`

  Sets the indicator to the "on" state.

`flash`

  Causes the button to flash from the normal to active state colors.

`invoke`

  Invokes the callback command as if the checkbuttons were clicked.

`toggle`

  Toggles the indicator from "on" to "off," or from "off" to "on."

18.4 The Button Widget |  | 18.6 The Radiobutton Widget