Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Gtk2 File Selection

by Cheater (Novice)
on Jul 26, 2007 at 20:15 UTC ( [id://628993]=perlquestion: print w/replies, xml ) Need Help??

Cheater has asked for the wisdom of the Perl Monks concerning the following question:

I'm attempting to use Gtk2 to add a GUI to a script. In order to do this, I need to add a widget that will allow the user to browse their computer for a file. Once they choose a file and hit the 'Submit' button, I need to have the path of the file stored in a variable. Due to limited resources availbe on Gtk2, I have had little success in accomplishing this. Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: Gtk2 File Selection
by phenom (Chaplain) on Jul 27, 2007 at 02:21 UTC
    This should work:
    my $file; my $dialog = Gtk2::FileChooserDialog->new( 'Select a File', undef, 'open', 'gtk-cancel' => 'cancel', 'gtk-ok' => 'ok', ); if ( "ok" eq $dialog->run ) { $file = $dialog->get_filename; print "file = $file\n"; } $dialog->destroy;
    See the documentation page for more: FileChooserDialog.
      That code worked perfect. I have one last question. How can I make it so the user can only select files of a certain format (i.e. only image files)?
        you reject his choice, and re-present the dialog
Re: Gtk2 File Selection
by Anonymous Monk on Jul 27, 2007 at 08:37 UTC
Re: Gtk2 File Selection
by Anonymous Monk on Jul 27, 2007 at 08:32 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found