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

Dear Friends,

I have created a simple UI in my perl script with perl/Tk. All things works perfectly except one odd thing.

i.e.

I have used "getOpenFile" dialog box for prompting the file from user. In this I have made option for selecting two file types, say e.g. ".doc" and ".xls"

Default is ".doc"

In a selected folder, if I select the other file type, it will not show anything on the selected folder unless I pressed enter button, whereas, in Windows XP all other applications changes the folder view automatically as per the selected file types

What I have missed, please help me to fix this in my tool

My code is as follows:

$xlsFileName = ""; my @types = (["3d Files",'.3d'], ["Excel Files",'.xls'], ["All fil +es", '*']); $xlsFileName = $mw->getOpenFile(-filetypes => \@types, -title=>'fi +le to read', -initialdir => $xlsFileName); $mw->Unbusy; return 'Cancel' unless($xlsFileName); $message = "Selected File: $xlsFileName"; $mw -> update;

Thanks in Advance

srikrishnan

Replies are listed 'Best First'.
Re: Doubt with getOpenFile
by stefbv (Priest) on Apr 29, 2010 at 09:07 UTC

    It is working fine for me on Linux, but I think the '-initialdir' option should be '.' or a dir name.

    I made a complete working example so other monks can test more easily :)

    use strict; use warnings; use Tk; my $mw = MainWindow->new; $mw->Button( -text => 'Select file', -width => 10, -command => \&select_file, )->pack(-side => 'left', -padx => 2); MainLoop; sub select_file { my @types = (["Perl files",'.pl'], ["Text files",'.txt'], ["All fi +les", '*']); my $xlsFileName = $mw->getOpenFile( -filetypes => \@types, -title =>'file to read', -initialdir => '.', ); # $mw->Unbusy; return unless $xlsFileName; print "Selected File: $xlsFileName\n"; # $mw -> update; }

    Regards, Stefan

    Update: Reintroduced the "return unless" line