Version 8 of chooseColor

Updated 2003-02-26 02:10:52

http://purl.org/tcl/home/man/tcl8.4/TkCmd/chooseColor.htm

aka tk_chooseColor


A minimal example:

 button .b_fg -text "Set Foreground Color" -command {fg_color}
 button .b_bg -text "Set Background Color" -command {bg_color}
 label .l -text "Foreground Color on Background Color"

 grid .b_fg .b_bg -sticky ew
 grid .l -row 1 -columnspan 2 -sticky ew

 proc fg_color { } {
        set color [tk_chooseColor]
        .l configure -fg $color
        }

 proc bg_color { } {
        set color [tk_chooseColor]
        .l configure -bg $color
        }

 wm title . "tk_chooseColor Example"

RS: A style note - no doubt this works as planned, but for more reusable (and also more compact) code, why not pass in the target widget, and the target attribute as well?

 button .b_fg -text "Set Foreground Color" -command {color .l -fg}
 button .b_bg -text "Set Background Color" -command {color .l -bg}
 label .l -text "Foreground Color on Background Color"

 grid .b_fg .b_bg -sticky ew
 grid .l -row 1 -columnspan 2 -sticky ew

 proc color {w what} {
        set color [tk_chooseColor]
        $w configure $what $color
 }

getSaveFile


Category Dialog - Tk syntax help - Arts and Crafts of Tcl-Tk Programming