
- Tcl Tutorial
- 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 Tutorial
- 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 - Selection Widgets
Selection widgets are used to select different options in a Tk application. The list of available selection widgets are as shown below.
Sr.No. | Widgets & Description |
---|---|
1 | Radiobutton
Widget that has a set of on/off buttons and labels, one of which may be selected. |
2 | Checkbutton
Widget that has a set of on/off buttons and labels, many of which may be selected. |
3 | Menu
Widget that acts as holder for menu items. |
4 | Listbox
Widget that displays a list of cells, one or more of which may be selected. |
A simple Tk example is shown below using selection widgets −
#!/usr/bin/wish grid [frame .gender ] grid [label .label1 -text "Male" -textvariable myLabel1 ] grid [radiobutton .gender.maleBtn -text "Male" -variable gender -value "Male" -command "set myLabel1 Male"] -row 1 -column 2 grid [radiobutton .gender.femaleBtn -text "Female" -variable gender -value "Female" -command "set myLabel1 Female"] -row 1 -column 3 .gender.maleBtn select grid [label .myLabel2 -text "Range 1 not selected" -textvariable myLabelValue2 ] grid [checkbutton .chk1 -text "Range 1" -variable occupied1 -command {if {$occupied1 } { set myLabelValue2 {Range 1 selected} } else { set myLabelValue2 {Range 1 not selected} } }] proc setLabel {text} { .label configure -text $text }
When we run the above program, we will get the following output −

Advertisements