|
|
|
|
|
As when creating any widget, the checkbutton is created using a method named after the capitalized version of the widget name, Checkbutton, invoked from the parent widget. The basic usage looks like this: |
|
|
|
 |
|
|
|
|
$cb = $parentwidget->Checkbutton( [ option => value, ... ] )->pack; |
|
|
|
|
|
|
|
|
In addition to having an indicator with a status, the checkbutton also can have a callback that uses the -command option associated with it. When the checkbutton is clicked (regardless of the indicator's status), the callback is invoked. However, it isn't always necessary to associate a callback for radiobuttons and checkbuttons since you can just check the status of the radiobutton or checkbutton later on in the program. |
|
|
|
|
|
|
|
|
The boolean status of the checkbutton is stored in a variable that you give via the -variable option when it is created. Each checkbutton should have its own status stored in its own unique variable. When the checkbutton is clicked, the status is updated. In addition, any callback associated with the -command option is invoked (regardless of the new status of the checkbutton). The options that change a checkbutton's behavior are listed below and explained in greater detail afterwards. |
|
|
|
|
|
|
|
|
The following checkbutton options work exactly the same as a standard button, so I won't go over them in detail again. Refer to Chapter 3, for complete descriptions of these options: -activebackground, -activeforeground, -anchor, -background, -borderwidth, -cursor, -disabledforeground, -font, -foreground, -height, -highlightbackground, -highlightcolor, -highlightthickness, -justify, -padx, -pady, -state, -takefocus, -text, -textvariable, -underline, -width, and -wraplength. |
|
|
|
|
|
|
|
|
The rest of the options behave a little differently or are exclusive to the checkbutton widget. They are covered in the following list. Some options deal with only the indicator (such as -selectimage). Remember that the -state option refers to the entire checkbutton widget, and the status of the indicator is governed by the options -onvalue, -offvalue, -indicatoron, and -variable. |
|
|
|
 |
|
|
|
|
-activebackground => color
Sets the color the widget's background should be when the mouse is over it. |
|
|
|
 |
|
|
|
|
-activeforeground => color
Sets the color the widget's text should be when the mouse is over it. |
|
|
|
 |
|
|
|
|
-anchor => 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw' | 'center'
Sets the position of the text within the widget. Most noticeable when the widget is resized larger. |
|
|
|
|