Posted to tcl by GPS at Sat Aug 04 07:56:09 GMT 2007view raw

  1. proc set-scroll-region {canvas id} {
  2. set subwin [$canvas itemcget $id -window]
  3. set w [max [winfo reqwidth $subwin] [winfo width $canvas]]
  4. set h [max [winfo reqheight $subwin] [winfo height $canvas]]
  5. $canvas itemconfigure $id -width $w -height $h
  6.  
  7. set whalf [expr {$w / 2}]
  8. set hhalf [expr {$h / 2}]
  9. $canvas configure -scrollregion [list -$whalf -$hhalf $whalf $hhalf]
  10. }
  11.  
  12.  
  13. In proc ui I have this:
  14. grid [canvas $t.v.bottom.canvas \
  15. -xscrollcommand [list $t.v.bottom.xview set] \
  16. -yscrollcommand [list $t.v.bottom.yview set]] -row 0 -column 1 -sticky nesw
  17.  
  18. set subwin [frame $t.v.bottom.canvas.area]
  19.  
  20. set id [$t.v.bottom.canvas create window 0 0 -window $subwin]
  21. bind $subwin <Configure> [list set-scroll-region $t.v.bottom.canvas $id]
  22.  
  23.  
  24. Do you have any idea what I'm doing wrong? It seems to work some of the time, but other times (seemingly randomly) it doesn't. I assume it's some sort of idle callback issue with geometry management, but I'm not sure how to fix it.