Tk - Check Button Widget
Tk check button is used to create multiple selectable items in the form of check boxes. The syntax for check button widget is shown below −
checkbutton checkbuttonName options
Options
The options available for the check button widget are listed below in the following table −
| Sr.No. | Syntax & Description |
|---|---|
| 1 | -font fontDescriptor Used to set font for widget. |
| 2 | -height number Used to set height for widget. |
| 3 | -command action Sets the command action for button. |
| 4 | -text text Sets the text for widget. |
| 5 | -width number Sets the width for widget. |
| 6 | -variable variableName Sets the variable for widget. |
A simple Tk example for check button is shown below −
#!/usr/bin/wish
grid [label .myLabel1 -text "Range 20-30 not selected" -textvariable myLabelValue1 ]
grid [checkbutton .chk1 -text "Range 20-30" -variable occupied1 -command {if {$occupied1 } {
set myLabelValue1 {Range 20-30 selected}
} else {
set myLabelValue1 {Range 20-30 not selected}
} }]
grid [label .myLabel2 -text "Range 30+ not selected" -textvariable myLabelValue2 ]
grid [checkbutton .chk2 -text "Range 20-30" -variable occupied2 -command {if {$occupied2 } {
set myLabelValue2 {Range 30+ selected}
} else {
set myLabelValue2 {Range 30+ not selected}
} }]
When we run the above program, we will get the following output −
When we click the check button1 and check button2, we will get the following output −
tk_selection_widgets.htm
Advertisements