3 # This demonstration script creates a toplevel window containing
4 # several checkbuttons.
6 if {![info exists widgetDemo
]} {
7 error "This script should be run from the \"widget\" demo."
15 wm title
$w "Checkbutton Demonstration"
16 wm iconname
$w "check"
19 label $w.msg
-font $font -wraplength 4i
-justify left
-text "Four checkbuttons are displayed below. If you click on a button, it will toggle the button's selection state and set a Tcl variable to a value indicating the state of the checkbutton. The first button also follows the state of the other three. If only some of the three are checked, the first button will display the tri-state mode. Click the \"See Variables\" button to see the current values of the variables."
22 ## See Code / Dismiss buttons
23 set btns
[addSeeDismiss
$w.buttons
$w [list safety wipers brakes sober
]]
24 pack $btns -side bottom
-fill x
26 checkbutton $w.b0
-text "Safety Check" -variable safety
-relief flat
\
29 -tristatevalue "partial"
30 checkbutton $w.b1
-text "Wipers OK" -variable wipers
-relief flat
31 checkbutton $w.b2
-text "Brakes OK" -variable brakes
-relief flat
32 checkbutton $w.b3
-text "Driver Sober" -variable sober
-relief flat
33 pack $w.b0
-side top
-pady 2 -anchor w
34 pack $w.b1
$w.b2
$w.b3
-side top
-pady 2 -anchor w
-padx 15
36 ## This code makes $w.b0 function as a tri-state button; it's not
37 ## needed at all for just straight yes/no buttons.
40 proc tristate_check
{n1 n2 op
} {
41 global safety wipers brakes sober in_check
46 if {$n1 eq
"safety"} {
47 if {$safety eq
"none"} {
51 } elseif
{$safety eq
"all"} {
57 if {$wipers == 1 && $brakes == 1 && $sober == 1} {
59 } elseif
{$wipers == 1 ||
$brakes == 1 ||
$sober == 1} {
68 trace variable wipers w tristate_check
69 trace variable brakes w tristate_check
70 trace variable sober w tristate_check
71 trace variable safety w tristate_check