[Tutor] Re: Question about tkFileDialog

Abel Daniel abli at freemail.hu
Wed Oct 22 15:31:01 EDT 2003


[...Tkinter root window appearing when using tkFileDialog.askdirectory()...]

> 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?

Well, I can show a workaround:

import Tkinter
import tkFileDialog

Tkinter.Tk().withdraw()
projectFolder = tkFileDialog.askdirectory()

... rest of program ...

The problem is that tkFileDialog creates not only the window you need,
but also a 'root window'. I guess it's because tkFileDialog creates a
new window, (so that it works even if you have other Tkinter windows
around), but Tkinter insits on creating the root window even if no
widgets are placed in it. For example 

import Tkinter
Tkinter.Toplevel()

gives _two_ windows, one is the 'root window' (which isn't special in
any way except thats the default window to place widgets in) and the
other is the Toplevel window we actually wanted.

I'm pretty suprised tkFileDialog has a bug like this. Anyway, in the
workaround, the line

Tkinter.Tk().withdraw()

explicitly creates this window, and immediatelly hides it.

-- 
Abel Daniel






More information about the Tutor mailing list