3 # This demonstration script prompts the user to select a color.
5 if {![info exists widgetDemo
]} {
6 error "This script should be run from the \"widget\" demo."
14 wm title
$w "Color Selection Dialog"
15 wm iconname
$w "colors"
18 label $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."
21 ## See Code / Dismiss buttons
22 set btns
[addSeeDismiss
$w.buttons
$w]
23 pack $btns -side bottom
-fill x
25 button $w.back
-text "Set background color ..." \
27 "setColor $w $w.back background {-background -highlightbackground}"
28 button $w.fore
-text "Set foreground color ..." \
30 "setColor $w $w.back foreground -foreground"
32 pack $w.back
$w.fore
-side top
-anchor c
-pady 2m
34 proc setColor
{w
button name
options} {
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
45 proc setColor_helper
{w
options color
} {
46 foreach option $options {
48 $w config
$option $color
51 foreach child
[winfo children
$w] {
52 setColor_helper
$child $options $color