Posted to tcl by dkf at Fri Feb 11 10:13:29 GMT 2011view raw

  1. # Basic scrollable container setup
  2. package require Tk
  3. canvas .c -width 100 -height 100 -yscrollcommand {.s set}
  4. scrollbar .s -orient vertical -command {.c yview}
  5. pack .c .s -fill y -expand 1 -side left -padx 2 -pady 2
  6. set w .c.f
  7. .c create window 0 0 -window [frame $w] -anchor nw -width 100 -height 150
  8. bind $w <Configure> {.c configure -scrollregion [list 0 0 %w %h]}
  9.  
  10. # Basic content; scrollable windows *must* be children of scroller
  11. label $w.l -text "Just so you\nknow it is\nscrolled" -background yellow
  12. pack $w.l -expand 1 -fill both
  13.  
  14. # The problem...
  15. .c configure -relief sunken -borderwidth 2
  16. # ...is that now the label can overlap that border!