Upgrade to Tcl/Tk 8.5b2
[msysgit.git] / mingw / lib / tk8.5 / demos / check.tcl
blob9c39153932e053a3b61d1a9e24c6c047f708d03a
1 # check.tcl --
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."
12 package require Tk
14 set w .check
15 catch {destroy $w}
16 toplevel $w
17 wm title $w "Checkbutton Demonstration"
18 wm iconname $w "check"
19 positionWindow $w
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."
22 pack $w.msg -side top
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 \
29 -onvalue "all" \
30 -offvalue "none" \
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.
41 set in_check 0
42 proc tristate_check {n1 n2 op} {
43 global safety wipers brakes sober in_check
44 if {$in_check} {
45 return
47 set in_check 1
48 if {$n1 eq "safety"} {
49 if {$safety eq "none"} {
50 set wipers 0
51 set brakes 0
52 set sober 0
53 } elseif {$safety eq "all"} {
54 set wipers 1
55 set brakes 1
56 set sober 1
58 } else {
59 if {$wipers == 1 && $brakes == 1 && $sober == 1} {
60 set safety all
61 } elseif {$wipers == 1 || $brakes == 1 || $sober == 1} {
62 set safety partial
63 } else {
64 set safety none
67 set in_check 0
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