use strict; use warnings; use Tk; my $mw = MainWindow->new; $mw->Button( -text => 'Select file', -width => 10, -command => \&select_file, )->pack(-side => 'left', -padx => 2); MainLoop; sub select_file { my @types = (["Perl files",'.pl'], ["Text files",'.txt'], ["All files", '*']); my $xlsFileName = $mw->getOpenFile( -filetypes => \@types, -title =>'file to read', -initialdir => '.', ); # $mw->Unbusy; return unless $xlsFileName; print "Selected File: $xlsFileName\n"; # $mw -> update; }