'''WISH Color Picker Plus''' megawidget http://www.geocities.com/pa_mcclamrock/ [http://www.geocities.com/pa_mcclamrock/wishcolorplus2008.gif] WISH Color Picker Plus is a fairly versatile megawidget for applying user-selected color schemes to Tk applications. It's included with all the applications you can download for free from http://www.geocities.com/pa_mcclamrock/ . You'll find it (wishcolorplus.tcl) in the /usr/local/lib/wishes subdirectory of the directory the tarball is unpacked into. The 2008 version of WISH Color Picker Plus requires Tk 8.5, and will set colors for just about any combination of standard Tk widgets, Ttk themed widgets, or both. It comes with several newly designed or re-done color schemes; any other color schemes, created with an older version of WISH Color Picker Plus, will need to be re-done for the newer version. To use WISH Color Picker Plus in an application, include the following code snippets, with whatever reasonable modifications you see fit (and let me know if you run into any problems). # Identify system directory ("$libdir") in which # WISH Color Picker Plus (wishcolorplus.tcl) will be found: set topdir /usr/local set libdir [file join $topdir lib wishes] # Identify user's subdirectory for color schemes: set wishdir [file join $env(HOME) .wishes] set colordir [file join $wishdir colorschemes] if {[file isdirectory $colordir] == 0} { file mkdir $colordir } # WISH Color Picker Plus isn't yet loaded: set coloron 0 # Initialize lists of Tk widgets for color display # (not all may be used by all programs; # colors of Ttk widgets will be derived # from window background color): set buttlist [list] ; # Buttons set texlist [list] ; # Text widgets set entlist [list] ; # Entry widgets set lublist [list] ; # Listboxes set spinlist [list] ; # Spinboxes set winlist [list] ; # Widgets to get window background color when disabled set headlist [list] ; # Emphasized labels set lightlist [list] ; # Light labels set checklist [list] ; # Checkbuttons and radiobuttons Add each Tk widget in the main program window to the appropriate widget list--for example: foreach butt [list .help .run .autoadd .autosel .colodisp .add .edit \ .unlist .sort .deselect .kill .quit] { lappend buttlist $butt } For subsidiary windows, frames, and whatnot, which won't appear when the main window is first opened, configure each Tk widget to use the appropriate foreground and background color, by way of the following global variables: * winfore, winback (window foreground and background) * selfore, selback (selection foreground and background) * buttfore, buttback (buttons, spinbox arrows) * textfore, textback (text, listbox, entry, spinbox value, "selectcolor" for checkbuttons and radiobuttons) * inacback (inactive selection background) * headfore, headback (emphasized labels) * lightfore, lightback (light labels, alternate lines in "striped" list displays) For example: entry .fix.dispname -width 36 -bg $::textback -fg $::textfore Create a button, menu item, or something to invoke a procedure that in turn will invoke WISH Color Picker Plus--for example: button .colodisp -text "Color Display" -command colodisp # Procedure to set up GUI box for configuring color display: proc colodisp {} { global color red green blue whatfig whatbutt colorlist colordir \ winback winfore selback selfore buttback buttfore textback \ textfore headback headfore lightback lightfore coloron wishdir \ libdir current_scheme bogomips if {$coloron == 0} { source [file join $libdir wishcolorplus.tcl] set coloron 1 } wishcolorplus ; # This does all the work--from WISH Color Picker Plus wm title .colo "WISH Command Center : WISH Color Picker Plus" } Create procedures to save and retrieve the "current_scheme" setting and, if desired, other variable settings (the procedure to save settings must be called "savefig"--for example: # Read configuration file, if there is one: set comfig [file join $wishdir comfig.tcl] if {[file readable $comfig]} { source $comfig } # Procedure to save configuration: proc savefig {} { global comfig set filid [open $comfig w] set figlines "# WISH Command Center configuration file (comfig.tcl)\ \n\nset proglist \[list $::proglist\]\ \nset autolist \[list $::autolist\]\ \nset deleteds \[list $::deleteds\]\ \nset current_scheme $::current_scheme" puts -nonewline $filid $figlines close $filid } Finally, to make sure there will be a default color scheme in any event, I include code like this in each application: # Load most recently used color scheme, if specified in configuration # file; if not, load "AntiqueBisque" color scheme as default--from here, # just in case color-scheme files have mysteriously vanished: if {[info exists current_scheme]} { source [file join $colordir $current_scheme.tcl] } elseif {[file readable [file join $colordir AntiqueBisque.tcl]]} { source [file join $colordir AntiqueBisque.tcl] } else { set current_scheme "AntiqueBisque" # For Tk widgets: set winback "bisque" set winfore "black" set selback "#FFD080" set selfore "black" set buttback "#F0B060" set buttfore "black" set textback "#FFFFF0" set textfore "black" set inacback "#C0A080" set linktex "#FF8000" set headback "#FFC060" set headfore "black" set lightback "#FFF0E4" set lightfore "black" tk_setPalette background $winback foreground $winfore \ selectBackground $selback selectForeground $selfore if {[info exists buttlist]} { foreach butt $buttlist { catch {$butt configure -bg $buttback -fg $buttfore} } } if {[info exists texlist]} { foreach tex $texlist { catch {$tex configure -bg $textback -fg $textfore} catch {$tex tag configure linklike -foreground $linktex -underline 1} catch {$tex configure -inactiveselectbackground $inacback} } } if {[info exists lublist]} { foreach lub $lublist { catch {$lub configure -bg $textback -fg $textfore} } } if {[info exists entlist]} { foreach ent $entlist { catch {$ent configure -bg $::textback -fg $textfore} } } if {[info exists headlist]} { foreach head $headlist { catch {$head configure -bg $::headback -fg $headfore} } } if {[info exists lightlist]} { foreach light $lightlist { catch {$light configure -bg $lightback -fg $lightfore} } } if {[info exists checklist]} { foreach check $checklist { catch {$check configure -selectcolor $textback} } } # For Ttk themed widgets: set themenames [ttk::style theme names] if {"AntiqueBisque" ni $themenames} { ttk::style theme create AntiqueBisque -parent clam } namespace eval ttk::theme::AntiqueBisque { variable colors array set colors { -disabledfg "#e4a080" -frame "#ffe4c4" -window "#fffff0" -dark "#f0b060" -darker "#f0b060" -darkest "#e48000" -lighter "#fff0e4" -lightest "#fff0e4" -selectbg "#ffd080" -selectfg "#000000" } ttk::style theme settings AntiqueBisque { ttk::style configure "." \ -background $colors(-dark) \ -foreground black \ -bordercolor $colors(-darkest) \ -darkcolor $colors(-dark) \ -lightcolor $colors(-lighter) \ -troughcolor $colors(-frame) \ -selectbackground $colors(-selectbg) \ -selectforeground $colors(-selectfg) \ -selectborderwidth 0 \ -font TkDefaultFont \ ; ttk::style map "." \ -background [list disabled $colors(-frame) \ active $colors(-lighter)] \ -foreground [list disabled $colors(-disabledfg)] \ -selectbackground [list !focus $colors(-darkest)] \ -selectforeground [list !focus white] \ ; # -selectbackground [list !focus "#847d73"] ttk::style configure TButton \ -anchor center -width -11 -padding 5 -relief raised ttk::style map TButton \ -background [list \ disabled $colors(-frame) \ pressed $colors(-darker) \ active $colors(-lighter)] \ -lightcolor [list pressed $colors(-darker)] \ -darkcolor [list pressed $colors(-darker)] \ -bordercolor [list alternate "#000000"] \ ; ttk::style configure Toolbutton \ -anchor center -padding 2 -relief flat ttk::style map Toolbutton \ -relief [list \ disabled flat \ selected sunken \ pressed sunken \ active raised] \ -background [list \ disabled $colors(-frame) \ pressed $colors(-darker) \ active $colors(-lighter)] \ -lightcolor [list pressed $colors(-darker)] \ -darkcolor [list pressed $colors(-darker)] \ ; ttk::style configure TCheckbutton \ -indicatorbackground "#fffff0" \ -indicatormargin {1 1 4 1} \ -padding 2 ; ttk::style configure TRadiobutton \ -indicatorbackground "#fffff0" \ -indicatormargin {1 1 4 1} \ -padding 2 ; ttk::style map TCheckbutton -indicatorbackground \ [list disabled $colors(-frame) pressed $colors(-frame)] ttk::style map TRadiobutton -indicatorbackground \ [list disabled $colors(-frame) pressed $colors(-frame)] ttk::style configure TMenubutton \ -width -11 -padding 5 -relief raised ttk::style configure TEntry -padding 1 -insertwidth 1 ttk::style map TEntry \ -background [list readonly $colors(-frame)] \ -bordercolor [list focus $colors(-selectbg)] \ -lightcolor [list focus "#6f9dc6"] \ -darkcolor [list focus "#6f9dc6"] \ ; ttk::style configure TCombobox -padding 1 -insertwidth 1 ttk::style map TCombobox \ -background [list active $colors(-lighter) \ pressed $colors(-lighter)] \ -fieldbackground [list {readonly focus} $colors(-selectbg) \ readonly $colors(-frame)] \ -foreground [list {readonly focus} $colors(-selectfg)] \ ; ttk::style configure TNotebook.Tab -padding {6 2 6 2} ttk::style map TNotebook.Tab \ -padding [list selected {6 4 6 2}] \ -background [list selected $colors(-frame) {} $colors(-darker)] \ -lightcolor [list selected $colors(-lighter) {} $colors(-dark)] \ ; # Treeview: ttk::style configure Heading \ -font TkHeadingFont -relief raised -padding {3} ttk::style configure Row -background $colors(-window) ttk::style configure Cell -background $colors(-window) ttk::style map Row \ -background [list selected $colors(-selectbg)] \ -foreground [list selected $colors(-selectfg)] ; ttk::style map Cell \ -background [list selected $colors(-selectbg)] \ -foreground [list selected $colors(-selectfg)] ; ttk::style map Item \ -background [list selected $colors(-selectbg)] \ -foreground [list selected $colors(-selectfg)] ; ttk::style configure TLabelframe \ -labeloutside true -labelmargins {0 0 0 4} \ -borderwidth 2 -relief raised ttk::style configure TProgressbar -background $colors(-frame) ttk::style configure Sash -sashthickness 6 -gripcount 10 } } ttk::setTheme AntiqueBisque } David McClamrock ---- !!!!!! %| [Category GUI] | [Category Widget] |% !!!!!!