#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::FileSelect; use Cwd; my $mw = MainWindow->new(); $mw->title("Some Window"); my $button = $mw->Button(-text => "Choose file", -command => sub {&selectFile($mw)}); $button->pack(-padx => 20, -pady => 20); MainLoop(); sub selectFile { my $mw = shift; my $diag = $mw->FileSelect(-directory => getcwd()); my $file = $diag->Show(); print "Selected file is: $file.\n"; }