[Tutor] Question about tkFileDialog

Michael Lange klappnase at freenet.de
Wed Oct 22 14:27:07 EDT 2003


On Wed, 22 Oct 2003 14:49:38 +0000
m.evanetich at att.net wrote:

> I am attempting to write a simple data consolidation script that opens files 
> in subtrees and combines the data into a single file at the root.  The script 
> starts by asking the user to specify a subtree.  Currently I am stumped by 
> the behavior of tkFileDialog. When I try:
> 
> >>> import tkFileDialog
> >>> projectFolder = tkFileDialog.askdirectory(initialdir='c:/projectDev',
> ...                                            mustexist=1,
> ...                                            title='Choose root directory 
> for the desired project.')
> >>> print projectFolder
> C:/projectDev/Foo
> 
> I get the desired result, but I also get a small application named tk on my 
> desktop and with a taskbar button that I cannot close as a side effect.  It 
> is disconcerting and I have not found a way to banish it.  Can anyone point 
> me to the relevant documentation or provide advice?
> 
> Thank you.
> 
Hi, 

the File Dialog window is called as a Toplevel window of a Tk window that is usually defined before.
If you haven't defined this root window before, it is automatically created (otherwise an exception had
to be raised). I must admit I have never tried this before, but that seems to be what happens here.
If you don't want to see the root window, try this:

>>> from Tkinter import *
>>> import tkFileDialog
>>> r = Tk()
>>> r.withdraw()# removes r from the screen
''
>>> f = tkFileDialog.askdirectory(<options>)
>>>etc.

Hope this helps

Michael



More information about the Tutor mailing list