Check Buttons

Check Buttons

Check buttons allow the user to choose one of two values in an application. One of the values is signaled as on for the check button, and the other is off. Each check button is connected to a global Tcl variable that receives its value; clicking the button on or off modifies the Tcl variable, and setting the variable in the underlying application modifies the appearance of the button.

The first example is very simple. It just shows the current value of the Tcl variable associated with a check button in a label:


Notice that the value of the label changes between 1 and 0 as the button is alternately checked and unchecked. The default values assigned to the underlying Tcl variable are one and zero, for the checked and unchecked state, respectively. You can also explicitly specify values for each state, as the next Tclet shows. In this example I specified that the off value is the string off, and the on value is the string on.


It's also possible to connect two or more check buttons to the same variable. If you click one of the buttons, the underlying variable changes, and the other button also.


Or, if you want, you can specify that the on value for one button is the off value for the other, as in the next example:


The last example on this page shows how a check button can be used by a running program to indicate the current state of the application:




comments?