in reply to Tk::Thumbnail --> callback help
I hate to be the first to respond to my own thread, but here goes.
I stole borrowed some code from the Tk::Thumbnail module and came up with an immature solution. However, 1) I hate reinventing the wheel 2) My hack of the original code is not as elegant.
Seems like there should be an easier way to do this that utilizes the existing Tk::Thumbnail.. My thought is that I need to subclass this module.. Tk::Thumbnail::Select but am unsure how I would do this.. The whole TK arena is still confusing to me and I am not very OOP literate.
Ohhh... Saints of Perl Wisdom, please bless this humble monk with guidance
use Tk; use TK::JPEG; use Tk::Photo; use strict; use warnings; sub mk_thumbnail { my $win = shift; my $img = shift; my $photo = $win->Photo( -file => $img ); my $thumb = $win->Photo; my $w = $photo->width; my $h = $photo->height; $w = ( $w /60 ); $h = ( $h /60 ); $thumb->copy( $photo, -subsample => ( $w, $h ) ); $photo->delete; return $thumb; } my $mw = MainWindow->new; my %images; my ($row, $col) = ( 0,0 ); foreach my $img ( <*.jpg>, <*.bmp> ) { my $thumb = mk_thumbnail ( $mw, $img ); $images{$img}=undef; my $frame = $mw->Labelframe( -text => $img)->grid( -row => $row, - +column => $col); my $lb1 = $frame->Label ( -image => $thumb)->pack; my $chk = $frame->Checkbutton ( -variable => \$images{$img} )->pac +k; $col++; if ($col == 4) { $col = 0; $row++; } } MainLoop; foreach my $k ( keys %images ){ print "$k:"; if ($images{$k} ) { print " selected.\n"; }else{ print " not selected.\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Tk::Thumbnail --> callback help
by zentara (Cardinal) on Apr 14, 2005 at 13:14 UTC | |
by zzspectrez (Hermit) on Apr 14, 2005 at 14:32 UTC | |
by zentara (Cardinal) on Apr 14, 2005 at 18:24 UTC |