3 # This demonstration script creates a toplevel window containing
4 # several checkbuttons.
6 # RCS: @(#) $Id: check.tcl,v 1.6 2007/10/15 21:06:17 dkf Exp $
8 if {![info exists widgetDemo
]} {
9 error "This script should be run from the \"widget\" demo."
17 wm title
$w "Checkbutton Demonstration"
18 wm iconname
$w "check"
21 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."
24 ## See Code / Dismiss buttons
25 set btns
[addSeeDismiss
$w.buttons
$w [list safety wipers brakes sober
]]
26 pack $btns -side bottom
-fill x
28 checkbutton $w.b0
-text "Safety Check" -variable safety
-relief flat
\
31 -tristatevalue "partial"
32 checkbutton $w.b1
-text "Wipers OK" -variable wipers
-relief flat
33 checkbutton $w.b2
-text "Brakes OK" -variable brakes
-relief flat
34 checkbutton $w.b3
-text "Driver Sober" -variable sober
-relief flat
35 pack $w.b0
-side top
-pady 2 -anchor w
36 pack $w.b1
$w.b2
$w.b3
-side top
-pady 2 -anchor w
-padx 15
38 ## This code makes $w.b0 function as a tri-state button; it's not
39 ## needed at all for just straight yes/no buttons.
42 proc tristate_check
{n1 n2 op
} {
43 global safety wipers brakes sober in_check
48 if {$n1 eq
"safety"} {
49 if {$safety eq
"none"} {
53 } elseif
{$safety eq
"all"} {
59 if {$wipers == 1 && $brakes == 1 && $sober == 1} {
61 } elseif
{$wipers == 1 ||
$brakes == 1 ||
$sober == 1} {
70 trace variable wipers w tristate_check
71 trace variable brakes w tristate_check
72 trace variable sober w tristate_check
73 trace variable safety w tristate_check