You could use Tk:Pane and put multiple canvases where you want, and fill them as you want. Here is something to look at.
#!/usr/bin/perl
use strict;
use Tk;
use Tk::Pane;
my %frames;
my %subframes;
my %labels;
my %buttons;
my $mw = MainWindow->new;
my $pane = $mw->Scrolled("Pane",
-scrollbars => 'se',
-sticky => 'nsew',
-bg => 'black',
-width => 300,
-height => 300
)->pack(-expand => 1, -fill => 'both');
my $realpane = $pane->Subwidget('scrolled');
my $xbar = $pane->Subwidget('xscrollbar');
my $ybar = $pane->Subwidget('yscrollbar');
$ybar->configure(-background=>'blue', -activebackground=>'blue',
-troughcolor => 'black', -width=> 50);
$xbar->configure(-background=>'green', -activebackground=>'green',
-troughcolor => 'black', -width=> 50);
foreach my $row (0 .. 3) {
$frames{$row} = $pane->Frame(-bg => 'black')->pack(
-padx => 5,
-pady => 5,
-expand => 1,
-fill => 'both',
-anchor => 'nw',
);
foreach my $col (0 .. 3) {
createTile($row, $col);
}
}
MainLoop;
sub createTile
{
my ($row, $col) = @_;
$subframes{$row}{$col}{'mainframe'} = $frames{$row}->Frame(
-bg => 'black')->pack(
-side => 'left',
-padx => 5,
-pady => 5,
-expand => 1,
-fill => 'both',
-anchor => 'nw',
);
my $frame = $subframes{$row}{$col}{'mainframe'};
my $sc = $frame->Scrolled('Canvas',
-scrollbars => 'osoe',
-scrollregion => [0, 0, 1200, 1200],
-width => 125,
-height => 125,
-background => randColor()
)->pack(-fill=>'both',-expand => 1, -side =>'top');
my $count = int(rand(6)) + 2;
foreach my $i (1 .. $count) {
my ($x, $y) = (randNumber(), randNumber());
my $size = randNumber();
$sc->createRectangle($x, $y, $x+$size, $y+$size,
-fill => randColor(),
-outline => 'black',
-width => 2
);
}
#miniframe for labels
$subframes{$row}{$col}{'subframe_a'} = $frame->Frame(
-bg => 'black')->pack(-side => 'top',-expand=> 1,-fill=>'bo
+th');
#mini frame for buttons
$subframes{$row}{$col}{'subframe_b'} = $frame->Frame(
-bg => 'black')->pack(-side => 'top',-expand=> 1,-fill=>'bo
+th');
#labels
$labels{$row}{$col}{1} = $subframes{$row}{$col}{'subframe_a'}->Labe
+l(
-text => "$row - $col" ,
-bg => 'black',
-fg => 'green',
)->pack(-side => 'left', -padx => 5);
$labels{$row}{$col}{2} = $subframes{$row}{$col}{'subframe_a'}->Label
+(
-text => "$row - $col" ,
-bg => 'black',
-fg => 'hotpink',
)->pack(-side => 'right', -padx => 5);
#buttons
$buttons{$row}{$col}{1} = $subframes{$row}{$col}{'subframe_b'}->Butt
+on(
-text => " Zoom Out ",
-command => sub { $sc->scale(qw/all 0 0 .5 .5/); }
)->pack(-side => 'left', -padx => 5);
$buttons{$row}{$col}{2} = $subframes{$row}{$col}{'subframe_b'}->Butt
+on(
-text => " Zoom In",
-command => sub { $sc->scale(qw/all 0 0 2 2/); }
)->pack(-side => 'right', -padx => 5);
}
sub randColor {
my @colors = qw(red yellow blue orange green purple);
return $colors[rand($#colors + 1)];
}
sub randNumber {
my ($max, $min) = (100, 10);
my $size = int(rand($max));
$size += $min if $size < $min;
return $size;
}