vscale.tcl 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # vscale.tcl --
  2. #
  3. # This demonstration script shows an example with a vertical 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 .vscale
  9. catch {destroy $w}
  10. toplevel $w
  11. wm title $w "Vertical Scale Demonstration"
  12. wm iconname $w "vscale"
  13. positionWindow $w
  14. label $w.msg -font $font -wraplength 3.5i -justify left -text "An arrow and a vertical scale are displayed below. If you click or drag mouse button 1 in the scale, you can change the size 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
  21. scale $w.frame.scale -orient vertical -length 284 -from 0 -to 250 \
  22. -command "setHeight $w.frame.canvas" -tickinterval 50
  23. canvas $w.frame.canvas -width 50 -height 50 -bd 0 -highlightthickness 0
  24. $w.frame.canvas create polygon 0 0 1 1 2 2 -fill SeaGreen3 -tags poly
  25. $w.frame.canvas create line 0 0 1 1 2 2 0 0 -fill black -tags line
  26. frame $w.frame.right -borderwidth 15
  27. pack $w.frame.scale -side left -anchor ne
  28. pack $w.frame.canvas -side left -anchor nw -fill y
  29. $w.frame.scale set 75
  30. proc setHeight {w height} {
  31. incr height 21
  32. set y2 [expr {$height - 30}]
  33. if {$y2 < 21} {
  34. set y2 21
  35. }
  36. $w coords poly 15 20 35 20 35 $y2 45 $y2 25 $height 5 $y2 15 $y2 15 20
  37. $w coords line 15 20 35 20 35 $y2 45 $y2 25 $height 5 $y2 15 $y2 15 20
  38. }