tkFileDialog module problem?

Eric Brunel eric.brunel at pragmadev.com
Thu Feb 13 04:31:43 EST 2003


Sam Marrocco wrote:
> Should calling the tkFileDialog module (askopenfilename) cause a tk 
> window to open *in addition* to the file dialog window? If not, is there 
> a way I can stop it?

You're probably doing something like:

from tkFileDialog import askopenfilename
myFile = askopenfilename()

Right?

In this case, you actually have an extra window appearing in addition to the 
file selection dialog. This is normal: it's Tk main window, that was 
automatically created since you didn't specify one and Tk cannot live without a 
main window (this is the basis of Tk: when you run it, it automatically creates 
a first main window).

To do what you want, you have to create the main window explicitely and make it 
disappear:

from Tkinter import *
from tkFileDialog import askopenfilename
## Explicitely create main window
mainWdw = Tk()
## Make it disappear
mainWdw.withdraw()
## Here we go again
myFile = askopenfilename()

This should do what you want.

HTH
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com





More information about the Python-list mailing list