Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: The right Tk file selecter

by crabbdean (Pilgrim)
on Mar 31, 2004 at 08:36 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-16 17:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found