summaryrefslogtreecommitdiffstats
path: root/library/demos/clrpick.tcl
blob: c20b98f5a34ef07b0fb9a42673f69b04e4505d79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# clrpick.tcl --
#
# This demonstration script prompts the user to select a color.
#
# RCS: @(#) $Id: clrpick.tcl,v 1.5 2004/12/21 11:56:35 dkf Exp $

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require Tk

set w .clrpick
catch {destroy $w}
toplevel $w
wm title $w "Color Selection Dialog"
wm iconname $w "colors"
positionWindow $w

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."
pack $w.msg -side top

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

button $w.back -text "Set background color ..." \
    -command \
    "setColor $w $w.back background {-background -highlightbackground}"
button $w.fore -text "Set foreground color ..." \
    -command \
    "setColor $w $w.back foreground -foreground"

pack $w.back $w.fore -side top -anchor c -pady 2m

proc setColor {w button name options} {
    grab $w
    set initialColor [$button cget -$name]
    set color [tk_chooseColor -title "Choose a $name color" -parent $w \
	-initialcolor $initialColor]
    if {[string compare $color ""]} {
	setColor_helper $w $options $color
    }
    grab release $w
}

proc setColor_helper {w options color} {
    foreach option $options {
	catch {
	    $w config $option $color
	}
    }
    foreach child [winfo children $w] {
	setColor_helper $child $options $color
    }
}