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

Hello, everybody.

I use Tk for building a GUI application for Win32, and there is file selection dialog box in my prog. Can anyone give me a hint: how should I implement the ability to choose multiple files/folders in this dialog? The manual reads that this function was added to this dialog recently, but no options/params that enable it are mentioned.

Thanks in advance,
Pavel

From Russia with love

  • Comment on Multiple file selection in Tk dialogbox

Replies are listed 'Best First'.
Re: Multiple file selection in Tk dialogbox
by buckaduck (Chaplain) on Jan 08, 2002 at 23:20 UTC
    The FileSelect widget appears to accept the "selectmode" configuration option. Its accepted values are the same as for Tk::Listbox. Here's a sample:
    use Tk::FileSelect; my $main = Tk::MainWindow->new; my $fsRef = $main->FileSelect(-directory => '/', -selectmode => 'extended'); my @files = $fsRef->Show; print foreach @files;
    The selectmode "extended" should allow you to select multiple files with Ctrl and Shift keys as you expect.

    buckaduck

Re: Multiple file selection in Tk dialogbox
by rbc (Curate) on Jan 08, 2002 at 23:07 UTC
    OOPS! I mean ...

    You can try something like this ...

    #!/usr/bin/perl -w use strict; use Tk; use Tk qw(exit); use Tk::DialogBox; my $FILE1 = "Please select a file"; my $FILE2 = "Please select a file"; my $top = MainWindow->new(); my $thebutton = $top->Button( -relief => "groove", -text => "Click Me ", -command => \&thebuttonCallback)->pack(); sub selectFile1Callback { my $userSelectedFile = $top->getOpenFile( -defaultextension => ".ctl", -filetypes => [ ['Control Files', '.ctl'], ['All Files', '*'] ], -initialdir => "C:\\TEMP", -initialfile => "Junk.txt", -title => "Select file 1" ); if ($userSelectedFile) { $FILE1 = $userSelectedFile; } } sub selectFile2Callback { my $userSelectedFile = $top->getOpenFile( -defaultextension => ".ctl", -filetypes => [ ['Control Files', '.ctl'], ['All Files', '*'] ], -initialdir => "C:\\TEMP", -initialfile => "Junk.txt", -title => "Select file 2" ); if ($userSelectedFile) { $FILE2 = $userSelectedFile; } } sub thebuttonCallback { my $d = $top->DialogBox( -title => "View Control File", -buttons => ["Done"] ); my $e1 = $d->add( 'Entry', -width => 60, -textvariable => \$FILE1 )->pack(); my $b1 = $d->add( 'Button', -width => 10, -text => 'File 1', -command => \&selectFile1Callback); my $e2 = $d->add( 'Entry', -width => 60, -textvariable => \$FILE2 )->pack(); my $b2 = $d->add( 'Button', -width => 10, -text => 'File 2', -command => \&selectFile2Callback); $e1->pack(); $b1->pack(); $e2->pack(); $b2->pack(); $d->Show(); } MainLoop();

    Previous post left out part of the code!!!
    There is a lot of room for improvement.
    You only need one selectFileCalback.
    Hope that helps

    --
    Its like a dog that can sing and dance.
    It's remarkable because it can do it.
    Not that it can do it well.
      FYI, you can update your posts, rather than posting twice.

      "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
      Thanks for your help, but the getOpenFile dialog box does not allow us to select multiple objects...

      Pavel

Re: Multiple file selection in Tk dialogbox
by rbc (Curate) on Jan 08, 2002 at 23:03 UTC
    You try something like this ...

    #!/usr/bin/perl -w use strict; use Tk; use Tk qw(exit); use Tk::DialogBox; my $FILE1 = "Please select a file"; my $FILE2 = "Please select a file"; my $top = MainWindow->new(); my $thebutton = $top->Button( -relief => "groove", -text => "Click Me ", -command => \&thebuttonCallback)->pack(); sub selectFile1Callback { my $userSelectedFile = $top->getOpenFile( -defaultextension => ".ctl", -filetypes => [ ['Control Files', '.ctl'], ['All Files', '*'] ], -initialdir => "C:\\TEMP", -initialfile => "Junk.txt", -title => "Select file 1" ); if ($userSelectedFile) { $FILE1 = $userSelectedFile; } } sub selectFile2Callback { my $userSelectedFile = $top->getOpenFile( -defaultextension => ".ctl", -filetypes => [ ['Control Files', '.ctl'], ['All Files', '*'] ], -initialdir => "C:\\TEMP", -initialfile => "Junk.txt", -title => "Select file 2" ); if ($userSelectedFile) { $FILE2 = $userSelectedFile; } }

    There is a lot of room for improvement.
    You only need one selectFileCalback.
    Hope that helps

    --
    Its like a dog that can sing and dance.
    It's remarkable because it can do it.
    Not that it can do it well.