1# button.tcl --
2#
3# This demonstration script creates a toplevel window containing
4# several button widgets.
5#
6# RCS: @(#) $Id: button.tcl,v 1.2.26.2 2007/05/30 13:24:01 das Exp $
7
8if {![info exists widgetDemo]} {
9    error "This script should be run from the \"widget\" demo."
10}
11
12set w .button
13catch {destroy $w}
14toplevel $w
15wm title $w "Button Demonstration"
16wm iconname $w "button"
17positionWindow $w
18
19label $w.msg -font $font -wraplength 4i -justify left -text "If you click on any of the four buttons below, the background of the button area will change to the color indicated in the button.  You can press Tab to move among the buttons, then press Space to invoke the current button."
20pack $w.msg -side top
21
22frame $w.buttons
23pack $w.buttons -side bottom -fill x -pady 2m
24button $w.buttons.dismiss -text Dismiss -command "destroy $w"
25button $w.buttons.code -text "See Code" -command "showCode $w"
26pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
27
28proc colorrefresh {w col} {
29    $w configure -bg $col
30    $w.buttons configure -bg $col
31    if {[tk windowingsystem] eq "aqua"} {
32	# set highlightbackground of all buttons in $w
33	set l [list $w]
34	while {[llength $l]} {
35	    set l [concat [lrange $l 1 end] [winfo children [set b [lindex $l 0]]]]
36	    if {[winfo class $b] eq "Button"} {
37		$b configure -highlightbackground $col
38	    }
39	}
40    }
41}
42
43button $w.b1 -text "Peach Puff" -width 10 \
44    -command [list colorrefresh $w PeachPuff1]
45button $w.b2 -text "Light Blue" -width 10 \
46    -command [list colorrefresh $w LightBlue1]
47button $w.b3 -text "Sea Green" -width 10 \
48    -command [list colorrefresh $w SeaGreen2]
49button $w.b4 -text "Yellow" -width 10 \
50    -command [list colorrefresh $w Yellow1]
51pack $w.b1 $w.b2 $w.b3 $w.b4 -side top -expand yes -pady 2
52