http://www.perlmonks.org?node_id=341248


in reply to The right Tk file selecter

Here is the result of some code I've just written to use in a program I'm writing - mostly a standard file or directory selector. Unfortunately it doesn't do multiple file selection, but you may get something out of it. Enjoy!

#!/usr/local/bin/perl use Tk; use Tk::FileDialog; use strict; use warnings; my $selected = ''; my $mw = new MainWindow; $mw->geometry(200 . 'x' . 100 . '+0+0'); $mw->Entry(-textvariable => \$selected )->pack(-expand => 1, -fill => 'x'); $mw->Button(-text => 'Browse', # set the last variable to 1 to only select directories -command => [\&selectme, $mw, 'archive.tar', 'h:', 0] )->pack(-expand => 1, -fill => 'x'); $mw->Button(-text => 'Exit', -command => sub {$mw->destroy} )->pack(-expand => 1, -fill => 'x'); MainLoop; sub selectme { my ($mw, $startfile, $startpath, $seldir) = @_; my $output = undef; ## configuration my($LoadDialog) = $mw->FileDialog(-Title =>'Select ...', -File => $startfile, -Path => $startpath, #-Chdir => 1, #-Create => 1, #-ShowAll => 1, -DisableShowAll => 1, #-Grab => 1, #-Horiz => 1, -SelDir => $seldir, #-FPat => '*', #-Geometry => '', ); $selected = $LoadDialog->Show(); if (!defined($startfile)) { $selected = "No file chosen!" } return $startfile; }

Dean
The Funkster of Mirth
Programming these days takes more than a lone avenger with a compiler. - sam
RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers