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; }

In reply to WorldCanvas in another canvas by Anonymous Monk

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.