radiobutton
Radiobuttons are buttons that are grouped together to select one value among many. Each button has a value, but only one in the button group is active at any one time. In Tcl/Tk this is achieved by creating a series of radiobutton that share an associated variable. Each button has a value. When a radiobutton is clicked on, the variable has that value and all the other buttons in the group are put into the off state. Similarly, setting the value of the variable is reflected in the state of the button group. An example is:
radiobutton .first -value one -text one -variable count radiobutton .second -value two -text two -variable count radiobutton .third -value three -text three -variable count
which creates three radiobuttons that are linked through the variable
count
. If button .second
is active, for example, then the
other two buttons are in the inactive state and count
has the
value two
. The following code sets the button group to make the
button .third
active and the rest inactive regardless of the current
state:
set count three
If the value of count
does not match any of the values of the
radiobuttons then they will all be off. For example executing the script
set count four
will turn all the radiobuttons off.