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;
};
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.