1# clrpick.tcl -- 2# 3# This demonstration script prompts the user to select a color. 4# 5# SCCS: @(#) clrpick.tcl 1.2 96/12/08 19:58:54 6 7set w .clrpick 8catch {destroy $w} 9toplevel $w 10wm title $w "Color Selection Dialog" 11wm iconname $w "colors" 12positionWindow $w 13 14label $w.msg -font $font -wraplength 4i -justify left -text "Press the buttons below to choose the foreground and background colors for the widgets in this window." 15pack $w.msg -side top 16 17frame $w.buttons 18pack $w.buttons -side bottom -fill x -pady 2m 19button $w.buttons.dismiss -text Dismiss -command "destroy $w" 20button $w.buttons.code -text "See Code" -command "showCode $w" 21pack $w.buttons.dismiss $w.buttons.code -side left -expand 1 22 23button $w.back -text "Set background color ..." \ 24 -command \ 25 "setColor $w $w.back background {-background -highlightbackground}" 26button $w.fore -text "Set foreground color ..." \ 27 -command \ 28 "setColor $w $w.back foreground -foreground" 29 30pack $w.back $w.fore -side top -anchor c -pady 2m 31 32proc setColor {w button name options} { 33 grab $w 34 set initialColor [$button cget -$name] 35 set color [tk_chooseColor -title "Choose a $name color" -parent $w \ 36 -initialcolor $initialColor] 37 if [string compare $color ""] { 38 setColor_helper $w $options $color 39 } 40 grab release $w 41} 42 43proc setColor_helper {w options color} { 44 foreach option $options { 45 catch { 46 $w config $option $color 47 } 48 } 49 foreach child [winfo children $w] { 50 setColor_helper $child $options $color 51 } 52} 53