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$..$/

In reply to Re: Tk: Aligning the items in seperate canvases by liverpole
in thread Tk: Aligning the items in seperate canvases by tcarmeli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.