ttkscale.tcl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # ttkscale.tcl --
  2. #
  3. # This demonstration script shows an example with a horizontal scale.
  4. if {![info exists widgetDemo]} {
  5. error "This script should be run from the \"widget\" demo."
  6. }
  7. package require Tk
  8. set w .ttkscale
  9. catch {destroy $w}
  10. toplevel $w -bg [ttk::style lookup TLabel -background]
  11. wm title $w "Themed Scale Demonstration"
  12. wm iconname $w "ttkscale"
  13. positionWindow $w
  14. pack [ttk::frame [set w $w.contents]] -fill both -expand 1
  15. ttk::label $w.msg -font $font -wraplength 3.5i -justify left -text "A label tied to a horizontal scale is displayed below. If you click or drag mouse button 1 in the scale, you can change the contents of the label; a callback command is used to couple the slider to both the text and the coloring of the label."
  16. pack $w.msg -side top -padx .5c
  17. ## See Code / Dismiss buttons
  18. set btns [addSeeDismiss $w.buttons [winfo toplevel $w]]
  19. pack $btns -side bottom -fill x
  20. ttk::frame $w.frame -borderwidth 10
  21. pack $w.frame -side top -fill x
  22. # List of colors from rainbox; "Indigo" is not a standard color
  23. set colorList {Red Orange Yellow Green Blue Violet}
  24. ttk::label $w.frame.label
  25. ttk::scale $w.frame.scale -from 0 -to 5 -command [list apply {{w idx} {
  26. set c [lindex $::colorList [tcl::mathfunc::int $idx]]
  27. $w.frame.label configure -foreground $c -text "Color: $c"
  28. }} $w]
  29. # Trigger the setting of the label's text
  30. $w.frame.scale set 0
  31. pack $w.frame.label $w.frame.scale