use Tk; use Tk::JPEG; use File::Glob ':glob'; my @jpgs = bsd_glob('*.jpg'); my $index = 0; my $mw = MainWindow->new(title => "JPEG"); my $b = $mw->Button()->pack(); $mw->after(1000, \&next_image); MainLoop; sub next_image { $b->configure(-image => undef); #effort to free memory eval { my $image = $mw->Photo(-format => 'jpeg', -file => $jpgs[$index]); $b->configure(-image => $image); $mw->configure(-title => $jpgs[$index]); $image = undef; #effort to free memory #undef($image); effort to free memory }; $mw->after(1000, \&next_image) if (++$index <= $#jpgs); }