use strict; use Tk; use Tk::Pane; my @tile; my @sc; my $x; my $i; my $initial_width=800; my $scale=1; my $mw = MainWindow->new; my $frame = $mw->Scrolled("Frame", -scrollbars => 's', -sticky => 'nsew', -bg => 'black', -width => 450, -height => 650 )->pack(qw/-expand 1 -fill both/); foreach $i (0 .. 3) { $tile[$i] = $frame->Frame( -bg => 'black' )->pack(); $sc[$i] = $tile[$i]->Scrolled('Canvas', -scrollbars => 'os', -scrollregion => [0, 0, $initial_width, 125], -width => 400, -height => 125, -background => randColor() )->pack(qw/-fill both -side top -expand 1/); $x = randNumber(); $sc[$i]->createRectangle($x, 50, $x+20, 90, -fill => randColor(), -outline => 'black', -width => 2, -tags => 'rect', ); $sc[$i]->createLine( 10,100, 790,100, -arrow => 'last'); for($x=50;$x<800;$x+=50){ $sc[$i]->createLine( $x,95, $x,105 ); } } $frame->Button( -text => " Zoom Out ", -width => 10, -command => sub { $scale*=0.8; foreach $i (0 .. 3) { $sc[$i]->scale(qw/all 0 0 .8 1/); $sc[$i]->configure(-scrollregion => [0, 0, int +($scale*$initial_width), 125]); } } )->pack(qw/-side left -padx 25/); $frame->Button( -text => " Zoom In ", -width => 10, -command => sub { $scale*=1.25; foreach $i (0 .. 3) { $sc[$i]->scale(qw/all 0 0 1.25 1/); $sc[$i]->configure(-scrollregion => [0, 0, int +($scale*$initial_width), 125]); } } )->pack(qw/-side left -padx 25/); $frame->Button( -text => " Align ", -width => 10, -command => [\&AlignAll], )->pack(qw/-side left -padx 25/); MainLoop; sub AlignAll{ my ($x1, $y1, $x2, $y2); my $i; my $location; foreach $i (0 .. 3) { ($x1, $y1, $x2, $y2) = $sc[$i]->bbox('rect'); $location =int(($x1+$x2)/2); warn("$location"); } } sub randColor { my @colors = qw(red yellow blue orange green purple cyan pink); return $colors[rand($#colors + 1)]; } sub randNumber { my ($max, $min) = (600, 200); my $size = int(rand($max)); $size += $min if $size < $min; return $size; }
In reply to Tk: Aligning the items in seperate canvases by tcarmeli
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |