use FindBin; .... my $image; my $mw = MainWindow->new(); our @files = glob("$FindBin::Bin/test/*.jpg"); my ($imageFile) = &GetNextFile(); my $button = $imageFrame->Button(-image => $image) ->pack(-fill => 'both', -expand => 1); $button->configure(-command => sub { ($imageFile) = &GetNextFile(); $button->configure(-image => $image); }); &Tk::MainLoop; # --------------------------------------- sub GetNextFile { while (my $file = shift(@files)) { next if -d "$inputDir/$file"; if ($file =~ /\.jpe?g$/) { unless (ref($image)) { eval { $image = $imageFrame->Photo(-file => "$file", -format => 'jpeg'); }; if ($@) { print "$file: $@\n"; $image = undef; next; } # if } # unless return (&File::Basename::basename($file)); } # while } # GetNextFile