- Tcl - Home
- Tcl - Overview
- Tcl - Environment Setup
- Tcl - Special Variables
- Tcl - Basic Syntax
- Tcl - Commands
- Tcl - Data Types
- Tcl - Variables
- Tcl - Operators
- Tcl - Decisions
- Tcl - Loops
- Tcl - Arrays
- Tcl - Strings
- Tcl - Lists
- Tcl - Dictionary
- Tcl - Procedures
- Tcl - Packages
- Tcl - Namespaces
- Tcl - File I/O
- Tcl - Error Handling
- Tcl - Built-in Functions
- Tcl - Regular Expressions
- Tk - Overview
- Tk - Environment
- Tk - Special Variables
- Tk - Widgets Overview
- Tk - Basic Widgets
- Tk - Layout Widgets
- Tk - Selection Widgets
- Tk - Canvas Widgets
- Tk - Mega Widgets
- Tk - Fonts
- Tk - Images
- Tk - Events
- Tk - Windows Manager
- Tk - Geometry Manager
- Tcl/Tk Useful Resources
- Tcl/Tk - Quick Guide
- Tcl/Tk - Useful Resources
- Tcl/Tk - Discussion
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