Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter askopenfilename() won't close

Tags:

I'm using the following code snippet to open a file chooser dialog box. It opens up the dialog fine, but after a file is chosen the dialog box stays open for the duration of the execution of the rest of my code, which is 3-4 min. I thought root.destroy() would close the open file dialog like it closes other Tkinter windows but that doesn't seem to be the case.

from tkinter import *
from tkinter.filedialog import askopenfilename

root = Tk()
root.withdraw()
file_path = askopenfilename()
root.destroy()

How would I go about getting the open file dialog to close after the file is chosen? I'm using version 3.4.3 on OSX 10.10

like image 268
mmmkay Avatar asked Aug 26 '15 02:08

mmmkay


1 Answers

For the sake of closing this question, here is the answer:

Call root.update() before askopenfilename()

like image 163
Jonah Fleming Avatar answered Oct 05 '22 11:10

Jonah Fleming