1# clrpick.tcl -- 2# 3# This demonstration script prompts the user to select a color. 4 5if {![info exists widgetDemo]} { 6 error "This script should be run from the \"widget\" demo." 7} 8 9package require Tk 10 11set w .clrpick 12catch {destroy $w} 13toplevel $w 14wm title $w "Color Selection Dialog" 15wm iconname $w "colors" 16positionWindow $w 17 18label $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." 19pack $w.msg -side top 20 21## See Code / Dismiss buttons 22set btns [addSeeDismiss $w.buttons $w] 23pack $btns -side bottom -fill x 24 25button $w.back -text "Set background color ..." \ 26 -command \ 27 "setColor $w $w.back background {-background -highlightbackground}" 28button $w.fore -text "Set foreground color ..." \ 29 -command \ 30 "setColor $w $w.back foreground -foreground" 31 32pack $w.back $w.fore -side top -anchor c -pady 2m 33 34proc setColor {w button name options} { 35 grab $w 36 set initialColor [$button cget -$name] 37 set color [tk_chooseColor -title "Choose a $name color" -parent $w \ 38 -initialcolor $initialColor] 39 if {[string compare $color ""]} { 40 setColor_helper $w $options $color 41 } 42 grab release $w 43} 44 45proc setColor_helper {w options color} { 46 foreach option $options { 47 catch { 48 $w config $option $color 49 } 50 } 51 foreach child [winfo children $w] { 52 setColor_helper $child $options $color 53 } 54} 55