hscale.tcl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # hscale.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 .hscale
  9. catch {destroy $w}
  10. toplevel $w
  11. wm title $w "Horizontal Scale Demonstration"
  12. wm iconname $w "hscale"
  13. positionWindow $w
  14. label $w.msg -font $font -wraplength 3.5i -justify left -text "An arrow and a horizontal scale are displayed below. If you click or drag mouse button 1 in the scale, you can change the length of the arrow."
  15. pack $w.msg -side top -padx .5c
  16. ## See Code / Dismiss buttons
  17. set btns [addSeeDismiss $w.buttons $w]
  18. pack $btns -side bottom -fill x
  19. frame $w.frame -borderwidth 10
  20. pack $w.frame -side top -fill x
  21. canvas $w.frame.canvas -width 50 -height 50 -bd 0 -highlightthickness 0
  22. $w.frame.canvas create polygon 0 0 1 1 2 2 -fill DeepSkyBlue3 -tags poly
  23. $w.frame.canvas create line 0 0 1 1 2 2 0 0 -fill black -tags line
  24. scale $w.frame.scale -orient horizontal -length 284 -from 0 -to 250 \
  25. -command "setWidth $w.frame.canvas" -tickinterval 50
  26. pack $w.frame.canvas -side top -expand yes -anchor s -fill x -padx 15
  27. pack $w.frame.scale -side bottom -expand yes -anchor n
  28. $w.frame.scale set 75
  29. proc setWidth {w width} {
  30. incr width 21
  31. set x2 [expr {$width - 30}]
  32. if {$x2 < 21} {
  33. set x2 21
  34. }
  35. $w coords poly 20 15 20 35 $x2 35 $x2 45 $width 25 $x2 5 $x2 15 20 15
  36. $w coords line 20 15 20 35 $x2 35 $x2 45 $width 25 $x2 5 $x2 15 20 15
  37. }