Maylon
Maylon

Reputation: 1

Tk open window issue/bug

If I type the following in the interpreter it works like a charm:

from Tkinter import Tk
from tkFileDialog import askopenfilename

Tk().withdraw()
fh = open(askopenfilename(), 'r') 

However, if I write/save/run a script with exactly the same commands, though it works (kind of like expected) the open window goes blank and remains on screen (after opening the selected file) and stays on top of everything.

As a result I need to click on the Python icon again in order for the window to close. At one point this stopped happening, but when I ran a script once without the Tk().withdraw() command the problem re-emerged.

I am running OSX Mavericks. If there is no way to fix the bug, is there any command in Python I can implement that closes this window?

Upvotes: 0

Views: 1039

Answers (1)

Ned Deily
Ned Deily

Reputation: 85035

See the accepted answer to this question When do I need to call mainloop in a Tkinter application?. You normally need to call Tk.mainloop() to start the event loop processing for Tk. But when you are running in the interactive interpreter, Python calls the Tk event processor for you, otherwise you would not be able to use Tkinter in the interactive interpreter as easily.

Upvotes: 2

Related Questions