Oh, oops don't need any "our" variables here... this was a quick hack from code a few years ago. But this runs with Perl 5.6/5.8/5.10 on Windows...should be ok on *nix also.#!/usr/bin/perl -w use strict; use Tk; my $current_file=(); our $mw = MainWindow->new; $mw->configure(-title=> "some title"); $mw->geometry("1000x400+0+0"); my $menu_f = $mw->Frame()->pack(-side=>'top',-fill=>'x'); my $menu_file = $menu_f->Menubutton (-text=>'File',-tearoff=>'false') ->pack(-side=>'left'); $menu_file->command(-label=>'Open', -command=> \&open_pdf); sub open_pdf { my @types = (["PDF files", [qw/.PDF /]], ["All files", '*'], ); $current_file= $mw->getOpenFile(-filetypes => \@types); print "$current_file\n"; } MainLoop();
Update
there are some things that I would change if I wrote the code now, like:
But at the end of the day, it is 2 lines of code to get a Tk GUI dialog up that will select a file.-command=> \&open_pdf ## better -command=> open_pdf(..params...)
In reply to Re: Perl Gui File browser select files
by Marshall
in thread Perl Gui File browser select files
by loztop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |