如果destroy后跟输入,Tkinter askopenfilename()将不会关闭

时间:2016-09-04 19:33:54

标签: macos python-3.x tkinter

我无法关闭Tkinter文件对话框。如果下游没有输入语句,则此Tkinter文件对话框将关闭。但有了它,它不会关闭,并崩溃应用程序。

通过一个消除过程,似乎root.destroy()命令下游的input()干扰了窗口关闭。

任何人都有修复?

以下是代码:

import tkinter
from tkinter import filedialog

###### THIS CODE WORKS #########
# Make a top-level instance and hide since it is ugly and big.
root = tkinter.Tk()
root.withdraw()

# Make it almost invisible - no decorations, 0 size, top left corner.
root.overrideredirect(True)
root.geometry('0x0+0+0')

# Show window again and lift it to top so it can get focus,
# otherwise dialogs will end up behind the terminal.
root.deiconify()
root.lift()
root.focus_force()

# get the file path of the trades to load.
new_file_path = filedialog.askopenfilename()

# Get rid of the top-level instance once to make it actually invisible.
root.destroy()

###### WHEN INPUT IS ADDED IT DOESNT WORK######
input('Testing testing testing  ')

我尝试在root.destroy之后添加time.sleep(1)。

我在这里试过这个解决方案: Tkinter askopenfilename() won't close

我正在使用OSX 10.11.4和Pycharm。

0 个答案:

没有答案