Macos Tkinter askopenfilename()赢得';如果销毁后有输入,则不能关闭

Macos Tkinter askopenfilename()赢得';如果销毁后有输入,则不能关闭,macos,python-3.x,tkinter,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 sinc

我无法关闭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)

我在这里尝试了解决方案:


我将OSX 10.11.4与Pycharm一起使用。

您对行为的描述与(不完整的)代码不匹配。在关闭模式对话框之前,
askopenfilename
调用不会返回。调用后的代码在调用完成之前不会执行。我在Win10上从空闲控制台和命令提示符控制台尝试了py 3.5.2和tk 8.6,其行为符合我的预期。该框用任一按钮关闭。什么操作系统、python版本和tcl/tk版本?(后者在Help=>About IDLE中通过IDLE显示。)我刚刚注意到链接的SO问题来自OSX用户,并且您有一个OSX标记。文件对话框的工作方式似乎与Windows上的完全不同。所以我既不能复制也不能帮助。抱歉。您似乎试图在没有完整Tkinter gui的情况下请求文件名,您是否尝试过中提出的解决方案?我刚刚尝试了该解决方案。如果输入是下游的,我也会遇到同样的问题。我刚刚测试的代码:从tkinter.filedialog导入askopenfilename root=tkinter.Tk()root.draw()filename=askopenfilename()输入('Testing')打印(filename)