in reply to The right Tk file selecter
#!/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; }
|
|---|