in reply to Tk: Aligning the items in seperate canvases

Hi tcarmeli,

Update:  My following "solution" wasn't adequate.  I was thinking you wanted to reposition the scrollbars and rectangles to the center, but of course that wasn't what you wanted at all.  I'm still trying to figure out a concise way to do this, but please don't go by what I originally wrote below ...

Update 2:  My reponse to zentara below gives a much better solution, but it's still not as good as the one by BrowserUK below.  His answer is clearly the best if you're willing to allow scrolling outside of the scrollable region; the rectangles stay centered after multiple zoom-in and zoom-out operations.  (Nice job, BrowserUK)

One possible way would be to retrieve the current coordinates of each scrollbar, in your AlignAll subroutine, calculate its width, and then use the same width but place it centered at 0.5, using the methods get and set:

sub AlignAll{ my ($x1, $y1, $x2, $y2); my $i; my $location; + foreach $i (0 .. 3) { # Reposition scrollbar to the middle my $sbar = $sc[$i]->Subwidget('xscrollbar'); my @range = $sbar->get(); my $size = ($range[1] - $range[0]) / 2; $sbar->set(0.5 - $size, 0.5 + $size); + ($x1, $y1, $x2, $y2) = $sc[$i]->bbox('rect'); $location =int(($x1+$x2)/2); warn("$location"); } }

There may well be a better/easier way to do this (if there is, my money's on the the Tk master :-)), but I believe this will do what you want.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: Tk: Aligning the items in seperate canvases
by wjw (Priest) on Nov 03, 2006 at 17:54 UTC
    Good try, but that just moves the scroll bars themselves without aligning the rectangles... . kind of wierd though, repositioning the scrollbars programaticly does not seem to change the screen that they control. Wish I knew enough about Tk to help. Will play with this... can see some neat applications for this. Cool!

    ...the majority is always wrong, and always the last to know about it...

Re^2: Tk: Aligning the items in seperate canvases
by tcarmeli (Beadle) on Nov 09, 2006 at 10:55 UTC
    Thanks for all of you!!!
    That was extremely helpful.