Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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...
\home
/home
c:\home
c:/home
C:/home
C:\home

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?

Comment on Tk getOpenFile, can't get -initialdir to work
Download Code
Re: Tk getOpenFile, can't get -initialdir to work
by Erez (Curate) 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.
      thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://678249]
Approved by Erez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-09-02 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls