pseudosocrates has asked for the wisdom of the Perl Monks concerning the following question:

This may be answerable with a general Tk knowledge (newbie here), or may be a module-related prob., but having issues with my script (the following is a pared down version -- note: To get the following script functioning, it needs to run in a folder with 'England' and 'Scotland' subfolders, each containing 'pic1.jpg' and 'pic2.jpg.)
My problem is that, when you select either England or scotland from the radiobutton, the Thumbnail is redrawn below the previous (rather than refreshing the contents of the thumbnails). I have tried $thumb->configure(-images=>[<@selection>]), but that came up all errors. Is there a workaround to, e.g., kill the Thumbnail instance, or perhaps refresh / empty the contents of the mainframe?

Any help/advice appreciated.
____________________________________
use Tk; use Tk::JPEG; use Tk::Thumbnail; use strict; my @countries = ("England", "Scotland"); my @justfiles = ("./England/pic1.jpg", "./Scotland/pic1.jpg", "./England/pic2.jpg", "./Scotland/pic2.jpg"); my @selection; my $country; my $mw = MainWindow->new; $mw->geometry("600x400"); my $menuframe = $mw->Frame(-bg => 'blue', -container => 0); $menuframe->pack(-side => 'left', -fill => 'y'); my $mainframe = $mw->Frame(-bg => 'darkblue', -container => 0); $mainframe->pack(-fill => 'both', -expand => 1); foreach (@countries) { $menuframe->Radiobutton ( -variable => \$country, -text => "$_", -value => "$_", -command => \&choosethumbs )->pack; } MainLoop; sub choosethumbs { @selection = grep(m/.*\/$country\/.*/, @justfiles); my $thumb = $mainframe->Thumbnail(-images => [<@selection>], -labels = +> 0, -width => '75', -height => '75', -background => 'black', -command = +> \&openwin)->pack; } sub openwin { my $tw = MainWindow->new; my $pic = $tw->Photo(-file=>$_[1]); $tw->Label(-image => $pic)->pack; };

Replies are listed 'Best First'.
Re: Tk::Thumbnail newbie issues
by pg (Canon) on Nov 13, 2003 at 04:07 UTC

    Make the following modification, and your problem should be resolved. (Solution tested with Perl 5.8.0 on win32)

    • Instead of defining $thumb inside sub choosethumbs, now define it outside the sub, could be at the beginning of your code:
      my $thumb;
    • Change your choosethumbs sub to this:
      sub choosethumbs { @selection = grep(m/.*\/$country\/.*/, @justfiles); if ($thumb) {#added four lines of code to destory the old thumb $thumb->destroy; $thumb = undef; } $thumb = $mainframe->Thumbnail(-images => \@selection, -labels =>0 +, -width => '75', -height => '75', -background => 'black', -command = +>\&openwin)->pack; }