Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: The right Tk file selecter

by crabbdean (Pilgrim)
on Mar 31, 2004 at 08:36 UTC ( #341248=note: print w/ replies, xml ) Need Help??


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


Comment on Re: The right Tk file selecter
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://341248]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2014-12-22 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (119 votes), past polls