Without alot of fancy logic, which tests all the positions, you can't perfectly align them with a program. Why? Because of the random placement, some of the canvases will hit the scroll limit and will not be able to moved in one direction(unless you do some trickery like expanding the scrollregion).

Check out the following sub, and test it a few times. Sometimes it will align, as long as there are not any random placements in the high range. Then find the line I've commented out, and uncomment it. That will always bring all 4 into the range, but not perfectly aligned. Like I said, you might be able to expand the scrollregion, so the scrollbar dosn't get locked into the far right position.

Another option which you might try, ( I'm thru fiddling with this :-) ) is to pick a x position on the screen, then scroll all canvases to the 0 position, then in a loop, scroll them 1 unit at a time until the boxe's screen position line up.

Someone else may figure something out, but unless you expand your scrollregion, the scrolled-window sliders will lock you up occaisionally.

sub AlignAll{ my ($x1, $y1, $x2, $y2); my $i; my $location; my %pos; foreach $i (0 .. 3) { ($x1, $y1, $x2, $y2) = $sc[$i]->bbox('rect'); $location =int(($x1+$x2)/2); warn("$location"); $pos{$i} = $location; $sc[$i]->xviewMoveto( $location/$initial_width ); } my @pos; foreach my $key (keys %pos ){ push @pos, $pos{$key}; } print "@pos\n"; my $max = &max(@pos); print "$max\n"; #move them all to the most right one, #since those are already at right scroll limit foreach $i (0 .. 3) { print $i," ",join ' ',$sc[$i]->xview(),"\n"; my $diff = $pos{$i} - $max; ############################################### ############################################### #try it with this line # $sc[$i]->xviewScroll($diff, 'units'); ############################################### } } sub max { my $max; for (@_) { $max = $_ if $_ > $max } return $max; } ########################################

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: Tk: Aligning the items in seperate canvases by zentara
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.