Update tk to version 8.5.11
[git/jnareb-git.git] / mingw / lib / tk8.5 / demos / check.tcl
blobc0720960ec8cde3375680ea27edcbc852ea071a6
1 # check.tcl --
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."
10 package require Tk
12 set w .check
13 catch {destroy $w}
14 toplevel $w
15 wm title $w "Checkbutton Demonstration"
16 wm iconname $w "check"
17 positionWindow $w
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."
20 pack $w.msg -side top
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 \
27 -onvalue "all" \
28 -offvalue "none" \
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.
39 set in_check 0
40 proc tristate_check {n1 n2 op} {
41 global safety wipers brakes sober in_check
42 if {$in_check} {
43 return
45 set in_check 1
46 if {$n1 eq "safety"} {
47 if {$safety eq "none"} {
48 set wipers 0
49 set brakes 0
50 set sober 0
51 } elseif {$safety eq "all"} {
52 set wipers 1
53 set brakes 1
54 set sober 1
56 } else {
57 if {$wipers == 1 && $brakes == 1 && $sober == 1} {
58 set safety all
59 } elseif {$wipers == 1 || $brakes == 1 || $sober == 1} {
60 set safety partial
61 } else {
62 set safety none
65 set in_check 0
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