添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Forget root window and want coming back ? root.withdraw() you lose root window can't go back ! – dsgdfg Aug 26, 2015 at 5:08 I'm not sure if it's different on OSX, but I'm more interested in closing the dialog box after the file selection, while the program finishes it's execution. If you add time.sleep(10) the dialog windows stays open while python waits 10 seconds. I want it to close immediately after file selection. – mmmkay Aug 26, 2015 at 16:27 @maccartm friend, can you show me root.deiconify() in code ? But Thank you for warning me .... – dsgdfg Aug 26, 2015 at 17:53 Just wanted to add that for me, on OSX and python2, calling root.update() after askopenfilename() works. – Plasma Aug 7, 2017 at 7:54

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.