Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The Tk::WorldCanvas in CPAN looks like a very useful tool. However, I have a problem using it that I am not sure how to solve. I am trying to make a scrolling list of thumbnail images, each scaled and centered. I want to place them on a scrolling canvas so I can add labels next to them, etc.
The problem is that the first few images come out centered properly and the last ones don't. I think it's because they are outside the scrolled region and they don't have proper size information. Is there a way to work around this? Thanks.
use strict; use Tk; use Tk::WorldCanvas; my $can_height = 50; my $can_spacing = $can_height + 2; my $can_label_padx = 2; my $can_width = 50; my $can_total = 5; my @canvasList = (); my $mainwin = MainWindow->new(); my $thumbholder = $mainwin->Scrolled('Canvas', -scrollbars => "e", -scrollregion => [0, 0, 0, $can_total*$can_spacing], -height => 2*$can_spacing, -width => 3*$can_width, -yscrollincrement=> $can_height, )->pack(-side => 'top'); for (my $i = 0; $i < $can_total; $i++) { makeThumbnail($i); } # Now let the WorldCanvas objects do a smart rescale. $mainwin->update(); foreach my $can (@canvasList) { $can->viewAll; } MainLoop; sub makeThumbnail { my $i = shift; my $thumbcan = $thumbholder->WorldCanvas(-height => $can_height, -width => $can_width); $thumbholder->createWindow(0, $can_spacing*$i, -anchor => "nw", -window => $thumbcan); $thumbholder->createText($can_width + $can_label_padx, $can_spacing*$i, -anchor => "nw", -text => "Image " . $i); # Fake triangle object for illustration purposes. my $color = 'black'; my $width = 1; my @path = (10,50,40,-20,66,80,10,50); $thumbcan->createLine(@path, -fill => $color, -width => $width); push @canvasList,$thumbcan; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: WorldCanvas in another canvas
by Anonymous Monk on Oct 31, 2002 at 21:16 UTC |