use strict; use warnings; use Tk; use utf8; my $mw = Tk::MainWindow->new; $mw -> Button(-text=>"Exit", -command => sub {exit(0)}) -> pack(-pady => 20); my $convert_bin; my $condition; if (!$condition) { my $bin_win = $mw->Toplevel(-title => 'A toplevel'); $bin_win->minsize(300, 200); $bin_win->update; $bin_win->raise; $bin_win->focus; $bin_win ->Label( -text => "Just testing", -font => 'bold',)->pack(-pady => 10); $bin_win ->Label( -text => "Please click browse and specify a random file.\nThe script will try and print the file path to c:/test/filepath.txt.",)->pack(-pady => 10); my $filepicker = sub { # this sub is launched when the Browse button is pressed, see further down $convert_bin = $mw ->getOpenFile( -title => "Please choose the file", -multiple => 0, ); mkdir "c:/test"; open (OUT, ">:encoding(UTF-8)", "c:/test/filepath.txt") or print "Can't open file: $!"; # this fails when the script is packed into an exe with PAR::Packer print OUT "File path: $convert_bin"; close OUT; $bin_win->destroy; }; # don't delete this ; my $buttbrowse = $bin_win -> Button(-text=>"Browse", -command =>[\&$filepicker]) -> pack(-pady => 20); } MainLoop;