home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tk42r2x.zip / TclTk / lib / tk4.2 / demos / clrpick.tcl.orig < prev    next >
Text File  |  1999-07-27  |  2KB  |  53 lines

  1. # clrpick.tcl --
  2. #
  3. # This demonstration script prompts the user to select a color.
  4. #
  5. # SCCS: @(#) clrpick.tcl 1.1 96/08/23 11:36:42
  6.  
  7. set w .clrpick
  8. catch {destroy $w}
  9. toplevel $w
  10. wm title $w "File Selection Dialogs"
  11. wm iconname $w "colors"
  12. positionWindow $w
  13.  
  14. 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."
  15. pack $w.msg -side top
  16.  
  17. frame $w.buttons
  18. pack $w.buttons -side bottom -fill x -pady 2m
  19. button $w.buttons.dismiss -text Dismiss -command "destroy $w"
  20. button $w.buttons.code -text "See Code" -command "showCode $w"
  21. pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
  22.  
  23. button $w.back -text "Set background color ..." \
  24.     -command \
  25.     "setColor $w $w.back background {-background -highlightbackground}"
  26. button $w.fore -text "Set foreground color ..." \
  27.     -command \
  28.     "setColor $w $w.back foreground -foreground"
  29.  
  30. pack $w.back $w.fore -side top -anchor c -pady 2m
  31.  
  32. proc setColor {w button name options} {
  33.     grab $w
  34.     set initialColor [$button cget -$name]
  35.     set color [tk_chooseColor -title "Choose a $name color" -parent $w \
  36.     -initialcolor $initialColor]
  37.     if [string compare $color ""] {
  38.     setColor_helper $w $options $color
  39.     }
  40.     grab release $w
  41. }
  42.  
  43. proc setColor_helper {w options color} {
  44.     foreach option $options {
  45.     catch {
  46.         $w config $option $color
  47.     }
  48.     }
  49.     foreach child [winfo children $w] {
  50.     setColor_helper $child $options $color
  51.     }
  52. }
  53.