Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Tk getOpenFile, can't get -initialdir to work

by mifflin (Curate)
on Apr 03, 2008 at 19:15 UTC ( #678249=perlquestion: print w/replies, xml ) Need Help??
mifflin has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to get the Tk getOpenFile widget to start out in a specific directory. The docs say to use the -initialdir option like this...
my $file = $Top->getOpenFile(-filetypes => $filetypes, -initialdir => +"C:/home");

I've tried...

However, it does not seem to work for me.

The behavior I see is this...
The widget always starts out in the program's directory.
If you select a file in a different directory then that directory becomes the default until you select a file in another different directory.
If you stop the perl script and then restart it later somehow getOpenFile remembers the directory you were at last.

Here is the perldoc on the option...

-initialdir => directory
Specifies that the files in directory should be displayed when the dialog pops up. If this parameter is not specified, then the files in the current working directory are displayed. This option may not always work on the Macintosh. This is not a bug. Rather, the General Controls control panel on the Mac allows the end user to override the application default directory.

Win Xp
Perl 5.8.8 build 820
Tk 804.027

Any ideas?

Replies are listed 'Best First'.
Re: Tk getOpenFile, can't get -initialdir to work
by Erez (Priest) on Apr 03, 2008 at 20:15 UTC

    According to this patch submission on ActiveState's programming forums it is a bug in Perl/Tk on Win32.

    The discussion is from March last year, it might be that a recent version already has this solved. If not, a link to the SVN repository is supplied as well.

    Software speaks in tongues of man.
    Stop saying 'script'. Stop saying 'line-noise'.
    We have nothing to lose but our metaphors.

Re: Tk getOpenFile, can't get -initialdir to work
by jdporter (Canon) on Apr 04, 2008 at 13:23 UTC

    Works just fine for me, but the path name appears to require backslashes. And remember that backslashes are special, and thus require escaping, in double-quoted strings.

    perl -MTk -e "MainWindow->new->getOpenFile( -initialdir => qq(c:\\prog +ram files) )"
    A word spoken in Mind will reach its own level, in the objective world, by its own weight
      I was taking my input from the chooseDirectory widget.
      chooseDirectory always uses forward slashes on xp.
      Passing its response through File::Spec->canonpath seems to do the trick.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://678249]
Approved by Erez
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-04-26 15:58 GMT
Find Nodes?
    Voting Booth?