
The proc
proc complexscroll {w width height {theight 20}} \
{
frame $w
canvas $w.c0 -height $theight -width $width \
-xscrollcommand [list $w.hs set] -bg beige \
-highlightthickness 0 -selectborderwidth 0 \
-bd 1 -relief solid
canvas $w.c1 -height $height -width $width \
-yscrollcommand [list $w.vs set] -bg white \
-highlightthickness 0 -selectborderwidth 0 \
-bd 1 -relief solid
scrollbar $w.hs -orient horizontal -command [list xview $w]
scrollbar $w.vs -command [list $w.c1 yview]
grid $w.c0 -row 0 -column 0 -sticky new
grid $w.c1 -row 1 -column 0 -sticky nsew
grid $w.hs -row 2 -column 0 -sticky new
grid $w.vs -row 0 -column 1 -sticky nse -rowspan 2
grid rowconfigure $w 1 -weight 1
grid columnconfigure $w 0 -weight 1
return $w
}
proc xview {w args} \
{
eval [linsert $args 0 $w.c0 xview]
eval [linsert $args 0 $w.c1 xview]
}The demo
wm title . "complex scroll"
pack [complexscroll .cs 250 150] -fill both -expand 1
set x 0
foreach title {firstname lastname address birthday occupation} \
{
.cs.c0 create text $x 8 -anchor nw -text " $title "
for {set y 8} {$y < 200} {incr y 24} \
{ .cs.c1 create text $x $y -anchor nw -text " $title " }
incr x 80
}
.cs.c0 configure -scrollregion [.cs.c0 bbox all]
.cs.c1 configure -scrollregion [.cs.c1 bbox all]Another proc if you want the scrollbars disapear when uneeded
proc complexscroll {w width height {theight 20}} \
{
frame $w
canvas $w.c0 -height $theight -width $width \
-xscrollcommand [list xset $w] -bg beige \
-highlightthickness 0 -selectborderwidth 0 \
-bd 1 -relief solid
canvas $w.c1 -height $height -width $width \
-yscrollcommand [list yset $w] -bg white \
-highlightthickness 0 -selectborderwidth 0 \
-bd 1 -relief solid
scrollbar $w.hs -orient horizontal -command [list xview $w]
scrollbar $w.vs -command [list yview $w]
grid $w.c0 -row 0 -column 0 -sticky new
grid $w.c1 -row 1 -column 0 -sticky nsew
grid $w.hs -row 2 -column 0 -sticky new
grid $w.vs -row 0 -column 1 -sticky nse -rowspan 2
grid rowconfigure $w 1 -weight 1
grid columnconfigure $w 0 -weight 1
return $w
}
proc xview {w args} \
{
eval [linsert $args 0 $w.c0 xview]
eval [linsert $args 0 $w.c1 xview]
}
proc xview {w args} \
{
eval [linsert $args 0 $w.c0 xview]
eval [linsert $args 0 $w.c1 xview]
}
proc yview {w args} \
{
eval [linsert $args 0 $w.c1 yview]
}
proc xset {w args} \
{
if {$args == "0 1"} \
{ grid forget $w.hs } \
else \
{
grid $w.hs -row 2 -column 0 -sticky wse
eval [linsert $args 0 $w.hs set]
}
}
proc yset {w args} \
{
if {$args == "0 1"} \
{ grid forget $w.vs } \
else \
{
grid $w.vs -row 0 -column 1 -sticky nse -rowspan 2
eval [linsert $args 0 $w.vs set]
}
}
