[Tutor] askopenfilename puzzle

Magnus Lyckå magnus@thinkware.se
Fri May 16 18:55:13 2003


At 00:06 2003-05-15 +0000, Lee Harr wrote:
>>I am taking over support on a python script written by a former college.
>>The script uses askopenfilename to select a file and everything works fine
>>but there's one thing that puzzles me.  After the first time you navigate to
>>a file it remembers where you were, even after you've exited the program,
>>shut down and rebooted the computer.  Someplace it's remembering where >you
>>last worked and I can't figure out how.
>askopenfilename is not a standard python function, so, maybe you
>could show us the code for it? Or at least some code?

Yes it is! But Tkinter is still poorly documented. It's
a function in tkFileDialog.py.

I'm not sure this magic happens in Python at all though. I would
guess it's Tcl/Tk that manipulates the registry if we're talking
Windows.

As you can see in tkFileDialog.py, askopenfile uses the class Open,
which contains the line: 'command = "tk_getOpenFile"'

I think you have to look up tk_getOpenFile in the Tcl/Tk documentation
to figure out the magic behind this, although I don't quite see the
solution here...

>-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. If the parameter specifies a relative 
>path, the return value will convert the relative path to an absolute path. 
>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.



--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program