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