Version 2 of Minimal scrolling canvas

Updated 2003-07-05 17:51:58

CL wanted a scrolling canvas model to which he could refer others. Mightily distressed that the first eight instances he came across in books and on the Web all were complicated or do things end-users consistently call "stupid" (scrollbars don't really behave properly, and so on)--or both!--he offers this example as an alternative:

    set height 400
    set width 600
    set borderwidth 2

    set hscroll .hscroll
    set vscroll .vscroll
    set canvas .c

    scrollbar $hscroll -orient horiz -command "$canvas xview"
    scrollbar $vscroll -command "$canvas yview"
    canvas $canvas -relief sunken -borderwidth $borderwidth \
                              -width $width -height $height \
                              -xscrollcommand "$hscroll set" \
                              -yscrollcommand "$vscroll set"
        # Ensure that window resizings retain scroll bars.
    pack $hscroll -side bottom -fill x
    pack $vscroll -side right -fill y
    pack $canvas -side right -fill both -expand 1
        # Put something on the canvas so we have some sense
        # of what we're seeing.
    $canvas create line 0 0 $width $height
    $canvas create line 0 $height $width 0
    $canvas configure -scrollregion [$canvas bbox all]

It will be interesting to see when its first fault emerges.