The purpose of a checkbutton widget (sometimes called “checkbox”) is to allow the user to read and select a two-way choice. The graphic above shows how checkbuttons look in the off (0) and on (1) state in one implementation: this is a screen shot of two checkbuttons using 24-point Times font.
The indicator is the part of the checkbutton that shows its state, and the label is the text that appears beside it.
You will need to create a control variable, an
instance of the
IntVar class, so
your program can query and set the state of the
checkbutton. See Section 22, “Control variables: the values behind the widgets”,
You can also use event bindings to react to user actions on the checkbutton; see Section 24, “Events”, below.
You can disable a checkbutton. This changes its appearance to “grayed out” and makes it unresponsive to the mouse.
You can get rid of the checkbutton indicator and make the whole widget a “push-push” button that looks recessed when it is set, and looks raised when it is cleared.
To create a checkbutton in an existing parent window or
w= Checkbutton (
option, ... )
The constructor returns a new
Checkbutton object. Options
|Background color when the checkbutton is under the cursor. See Section 4.3, “Colors”.|
|Foreground color when the checkbutton is under the cursor.|
|If the widget inhabits a space larger than it
needs, this option specifies where the checkbutton
will sit in that space. The default is
|The normal background color displayed behind the label and indicator. See Section 4.3, “Colors”.|
|To display a monochrome image on a button, set this option to a bitmap; see Section 4.7, “Bitmaps”.|
|The size of the border around the indicator. Default is 2 pixels. For possible values, see Section 4.1, “Dimensions”.|
|A procedure to be called every time the user changes the state of this checkbutton.|
|If you set this option to a cursor name (see Section 4.8, “Cursors”), the mouse cursor will change to that pattern when it is over the checkbutton.|
|The foreground color used to render the text of a disabled checkbutton. The default is a stippled version of the default foreground color.|
|The font used for the
|The color used
to render the
|The number of lines of text on the checkbutton. Default is 1.|
|The color of the focus highlight when the checkbutton does not have focus. See Section 23, “Focus: routing keyboard input”.|
|The color of the focus highlight when the checkbutton has the focus.|
|The thickness of the focus highlight. Default is 1. Set to 0 to suppress display of the focus highlight.|
|To display a graphic image on the button, set this option to an image object. See Section 4.9, “Images”.|
|Normally a checkbutton displays as its
indicator a box that shows whether the checkbutton
is set or not. You can get this behavior by
|Normally, a checkbutton's associated control
variable will be set to 0 when it is cleared (off).
You can supply an alternate value for the off state
by setting |
|Normally, a checkbutton's associated control
variable will be set to 1 when it is set (on). You
can supply an alternate value for the on state by
|How much space to leave to the left and right of the checkbutton and text. Default is 1 pixel. For possible values, see Section 4.1, “Dimensions”.|
|How much space to leave above and below the checkbutton and text. Default is 1 pixel.|
|With the default value,
|The color of the
checkbutton when it is set. Default is
|If you set this option to an image, that image will appear in the checkbutton when it is set. See Section 4.9, “Images”.|
|The default is
|The default is that the input focus (see Section 23, “Focus: routing keyboard input”) will pass through a checkbutton.
If you set |
|The label displayed next to the checkbutton.
Use newlines (|
|If you need to change the label on a checkbutton during execution, create a StringVar (see Section 22, “Control variables: the values behind the widgets”) to manage the current value, and set this option to that control variable. Whenever the control variable's value changes, the checkbutton's annotation will automatically change as well.|
|With the default value of -1, none of the characters of the text label are underlined. Set this option to the index of a character in the text (counting from zero) to underline that character.|
|The control variable that tracks the current
state of the checkbutton; see Section 22, “Control variables: the values behind the widgets”. Normally this
variable is an |
|The default width of a checkbutton is determined by the size of the displayed image or text. You can set this option to a number of characters and the checkbutton will always have room for that many characters.|
|Normally, lines are not wrapped. You can set this option to a number of characters and all lines will be broken into pieces no longer than that number.|
Methods on checkbuttons include:
Clears (turns off) the checkbutton.
Flashes the checkbutton a few times between its active and normal colors, but leaves it the way it started.
You can call this method to get the same actions that would occur if the user clicked on the checkbutton to change its state.
Sets (turns on) the checkbutton.
Clears the checkbutton if set, sets it if cleared.