use strict; use warnings; use Tk; use Tk::PNG; use Tk::JPEG; my @arr; push @arr, { name => 'sample.gif', type => 'gif'}; push @arr, { name => 'sample.png', type => 'png'}; push @arr, { name => 'sample.jpg', type => 'jpeg'}; foreach my $fh (@arr) { my $f = $fh->{name}; my $t = $fh->{type}; eval { my $mw = MainWindow->new; my $lbl = $mw->Label; my $photo = $mw->Photo(-file=>$f, -format=>$t ); print join ", ", $photo->formats(), "\n"; $lbl->configure(-image=>$photo); $lbl->pack; MainLoop; 1; } or do { warn "here: $@\n"; }; }