Posted to tcl by fvogel at Mon Aug 27 19:40:28 GMT 2007view raw

  1. set height 400
  2. set width 600
  3. set borderwidth 2
  4.  
  5. set hscroll .hscroll
  6. set vscroll .vscroll
  7. set canvas .c
  8.  
  9. scrollbar $hscroll -orient horiz -command "$canvas xview"
  10. scrollbar $vscroll -command "$canvas yview"
  11. canvas $canvas -relief sunken -borderwidth $borderwidth \
  12. -width $width -height $height \
  13. -xscrollcommand "$hscroll set" \
  14. -yscrollcommand "$vscroll set"
  15. # Ensure that window resizings retain scroll bars.
  16. pack $hscroll -side bottom -fill x
  17. pack $vscroll -side right -fill y
  18. pack $canvas -side right -fill both -expand 1
  19.  
  20. # Put something visible on the canvas
  21. # so we have a sense of what we're seeing.
  22. $canvas create line 0 0 $width $height
  23. $canvas create line 0 $height $width 0
  24.  
  25. frame $canvas.f
  26. $canvas conf -bg red
  27. $canvas.f conf -bg green
  28.  
  29. for {set ID 0} {$ID < 10} {incr ID} {
  30. label $canvas.f.lab1$ID -relief groove -takefocus 0 \
  31. -text hello \
  32. -width 24
  33. label $canvas.f.lab2$ID -relief groove -takefocus 0 \
  34. -text world \
  35. -width 5
  36. entry $canvas.f.expression$ID \
  37. -textvariable expression \
  38. -width 30
  39. grid $canvas.f.lab1$ID $canvas.f.lab2$ID $canvas.f.expression$ID -sticky ew
  40. }
  41. $canvas create window 0 0 -window $canvas.f -anchor nw
  42. update
  43. $canvas configure -scrollregion [$canvas bbox all]
  44.  
  45.