in reply to Directory and file selection with PERL/Tk
short demo program follows. Window will look like any other Windows application "file open", there is icon shortcut for Desktop, recently used, etc. All the drives on system are shown. You can filter by extension.I just put a .txt and .log button to show you how. It remembers where you were last time, so opening this window goes conveniently to last directory that you were in. I haven't used it for selecting multiple things but I'm sure it can do that too.
#!/usr/bin/perl -w use strict; use Tk; my $mw = MainWindow->new; $mw->geometry("400x400+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=> \&get_file); #other menu buttons shown here as examples ... #$menu_file->command(-label=>'Save', # -command=> \&save_log); #$menu_file->command(-label=>'Close', # -command=> \&close_log); #$menu_file->command(-label=>'Exit',-command=>\&exit_msg); sub get_file { my @types = (["Log files", [qw/.txt .log/]], ["All files", '*'], ); my $filepath = $mw->getOpenFile(-filetypes => \@types) or return(); print "$filepath selected\n"; return($filepath); } MainLoop;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Directory and file selection with PERL/Tk
by elef (Friar) on Mar 20, 2012 at 09:22 UTC | |
by jeri_rl (Initiate) on Jun 11, 2013 at 19:15 UTC | |
by elef (Friar) on Jun 13, 2013 at 12:02 UTC |