I have two canvases I am trying to have scrolled by the same horizontal scroll bar. I can get them to both react, but it seems, because the two canvases are not of the same width, the rate of scroll differs between the two - such that one canvas stops moving before the other. I need to them be in sync, as one is a graph of data and the other is an x-axis label. I am using grid for packing. I develop on a linux system.
I have also tried using 4 canvases instead of two: the graph, the main x-axis label, a small right and left portion. I did this to see if having them all the same scrollable width would make a difference, but no luck.
Any suggestions or ides?
Below is a dirty test script to demonstrate what it is I was trying to do.
Thanks!
------------------------------------------------
#! /bin/sh
# \
exec wish "$0" "$@"
proc BindView { which lists args } {
foreach l $lists {
eval {$l $which } $args
}
}
set mainw 200
set canvw 440
set sidew 30
set ht 25
set f [frame .f ]
set txt ""
scrollbar .f.scr -orient horizontal -command [list BindView xview [list .f.left .f.mid .f.right ] ]
#scrollbar .f.scr -orient horizontal -command [list BindView xview [list .f.left .f.right ] ]
scrollbar .f.scr2 -orient horizontal -command [list BindView xview [list .f.xc .f.midc ] ]
canvas .f.left -width $sidew -height $ht -highlightthickness 0 -borderwidth 0 \
-background red \
-xscrollcommand [list .f.scr set] \
-scrollregion "0 0 [expr $canvw - $mainw + $sidew ] $ht"
canvas .f.right -width $sidew -height $ht -highlightthickness 0 -borderwidth 0 \
-background blue \
-xscrollcommand [list .f.scr set] \
-scrollregion "0 0 [expr $canvw - $mainw + $sidew ] $ht"
canvas .f.mid -width $mainw -height $ht -highlightthickness 0 -borderwidth 0 \
-background white \
-xscrollcommand [list .f.scr set] \
-scrollregion "0 0 $canvw $ht"
canvas .f.midc -width $mainw -height $ht -highlightthickness 0 -borderwidth 0 \
-background pink \
-xscrollcommand [list .f.scr2 set] \
-scrollregion " 0 0 $canvw $ht "
canvas .f.xc -width [expr $mainw + ( 2 * $sidew) ] -height $ht \
-highlightthickness 0 -borderwidth 0 \
-background white \
-xscrollcommand [list .f.scr2 set] \
-scrollregion " 0 0 [expr $canvw + $sidew ] $ht "
grid .f.left -in $f -row 1 -column 1 -sticky nes
grid .f.mid -in $f -row 1 -column 2
grid .f.right -in $f -row 1 -column 3 -sticky nes
grid .f.scr -in $f -row 2 -column 2 -sticky news
grid .f.midc -in $f -row 3 -column 2
grid .f.xc -in $f -row 4 -column 1 -columnspan 3 -sticky news
grid .f.scr2 -in $f -row 5 -column 2 -sticky news
pack $f
set count 0
for { set ii 0 } { $ii <= $canvw } { incr ii 20 } {
set lx [expr $ii + $sidew ]
set rx [expr $ii - $mainw ]
set mx [expr $ii + $sidew ]
.f.mid create text $ii 4 -anchor n -text $count
.f.left create text $lx 4 -anchor n -text $count
.f.right create text $rx 4 -anchor n -text $count
.f.midc create text $ii 4 -anchor n -text $count
.f.xc create text $mx 4 -anchor n -text $count
incr count
}
I have also tried using 4 canvases instead of two: the graph, the main x-axis label, a small right and left portion. I did this to see if having them all the same scrollable width would make a difference, but no luck.
Any suggestions or ides?
Below is a dirty test script to demonstrate what it is I was trying to do.
Thanks!
------------------------------------------------
#! /bin/sh
# \
exec wish "$0" "$@"
proc BindView { which lists args } {
foreach l $lists {
eval {$l $which } $args
}
}
set mainw 200
set canvw 440
set sidew 30
set ht 25
set f [frame .f ]
set txt ""
scrollbar .f.scr -orient horizontal -command [list BindView xview [list .f.left .f.mid .f.right ] ]
#scrollbar .f.scr -orient horizontal -command [list BindView xview [list .f.left .f.right ] ]
scrollbar .f.scr2 -orient horizontal -command [list BindView xview [list .f.xc .f.midc ] ]
canvas .f.left -width $sidew -height $ht -highlightthickness 0 -borderwidth 0 \
-background red \
-xscrollcommand [list .f.scr set] \
-scrollregion "0 0 [expr $canvw - $mainw + $sidew ] $ht"
canvas .f.right -width $sidew -height $ht -highlightthickness 0 -borderwidth 0 \
-background blue \
-xscrollcommand [list .f.scr set] \
-scrollregion "0 0 [expr $canvw - $mainw + $sidew ] $ht"
canvas .f.mid -width $mainw -height $ht -highlightthickness 0 -borderwidth 0 \
-background white \
-xscrollcommand [list .f.scr set] \
-scrollregion "0 0 $canvw $ht"
canvas .f.midc -width $mainw -height $ht -highlightthickness 0 -borderwidth 0 \
-background pink \
-xscrollcommand [list .f.scr2 set] \
-scrollregion " 0 0 $canvw $ht "
canvas .f.xc -width [expr $mainw + ( 2 * $sidew) ] -height $ht \
-highlightthickness 0 -borderwidth 0 \
-background white \
-xscrollcommand [list .f.scr2 set] \
-scrollregion " 0 0 [expr $canvw + $sidew ] $ht "
grid .f.left -in $f -row 1 -column 1 -sticky nes
grid .f.mid -in $f -row 1 -column 2
grid .f.right -in $f -row 1 -column 3 -sticky nes
grid .f.scr -in $f -row 2 -column 2 -sticky news
grid .f.midc -in $f -row 3 -column 2
grid .f.xc -in $f -row 4 -column 1 -columnspan 3 -sticky news
grid .f.scr2 -in $f -row 5 -column 2 -sticky news
pack $f
set count 0
for { set ii 0 } { $ii <= $canvw } { incr ii 20 } {
set lx [expr $ii + $sidew ]
set rx [expr $ii - $mainw ]
set mx [expr $ii + $sidew ]
.f.mid create text $ii 4 -anchor n -text $count
.f.left create text $lx 4 -anchor n -text $count
.f.right create text $rx 4 -anchor n -text $count
.f.midc create text $ii 4 -anchor n -text $count
.f.xc create text $mx 4 -anchor n -text $count
incr count
}