1# radio.tcl --
2#
3# This demonstration script creates a toplevel window containing
4# several radiobutton widgets.
5#
6# RCS: @(#) $Id$
7
8if {![info exists widgetDemo]} {
9    error "This script should be run from the \"widget\" demo."
10}
11
12package require Tk
13
14set w .radio
15catch {destroy $w}
16toplevel $w
17wm title $w "Radiobutton Demonstration"
18wm iconname $w "radio"
19positionWindow $w
20label $w.msg -font $font -wraplength 5i -justify left -text "Three groups of radiobuttons are displayed below.  If you click on a button then the button will become selected exclusively among all the buttons in its group.  A Tcl variable is associated with each group to indicate which of the group's buttons is selected.  When the 'Tristate' button is pressed, the radio buttons will display the tri-state mode. Selecting any radio button will return the buttons to their respective on/off state. Click the \"See Variables\" button to see the current values of the variables."
21grid $w.msg -row 0 -column 0 -columnspan 3 -sticky nsew
22
23## See Code / Dismiss buttons
24set btns [addSeeDismiss $w.buttons $w [list size color align]]
25grid $btns -row 3 -column 0 -columnspan 3 -sticky ew
26
27labelframe $w.left -pady 2 -text "Point Size" -padx 2
28labelframe $w.mid -pady 2 -text "Color" -padx 2
29labelframe $w.right -pady 2 -text "Alignment" -padx 2
30button $w.tristate -text Tristate -command "set size multi; set color multi" \
31    -pady 2 -padx 2
32if {[tk windowingsystem] eq "aqua"} {
33    $w.tristate configure -padx 10
34}
35grid $w.left     -column 0 -row 1 -pady .5c -padx .5c -rowspan 2
36grid $w.mid      -column 1 -row 1 -pady .5c -padx .5c -rowspan 2
37grid $w.right    -column 2 -row 1 -pady .5c -padx .5c
38grid $w.tristate -column 2 -row 2 -pady .5c -padx .5c
39
40foreach i {10 12 14 18 24} {
41    radiobutton $w.left.b$i -text "Point Size $i" -variable size \
42	    -relief flat -value $i -tristatevalue "multi"
43    pack $w.left.b$i  -side top -pady 2 -anchor w -fill x
44}
45
46foreach c {Red Green Blue Yellow Orange Purple} {
47    set lower [string tolower $c]
48    radiobutton $w.mid.$lower -text $c -variable color \
49	    -relief flat -value $lower -anchor w \
50	    -command "$w.mid configure -fg \$color" \
51	-tristatevalue "multi"
52    pack $w.mid.$lower -side top -pady 2 -fill x
53}
54
55
56label $w.right.l -text "Label" -bitmap questhead -compound left
57$w.right.l configure -width [winfo reqwidth $w.right.l] -compound top
58$w.right.l configure -height [winfo reqheight $w.right.l]
59foreach a {Top Left Right Bottom} {
60    set lower [string tolower $a]
61    radiobutton $w.right.$lower -text $a -variable align \
62	    -relief flat -value $lower -indicatoron 0 -width 7 \
63	    -command "$w.right.l configure -compound \$align"
64}
65
66grid x $w.right.top
67grid $w.right.left $w.right.l $w.right.right
68grid x $w.right.bottom
69