【发布时间】:2019-12-05 20:30:46
【问题描述】:
我正在尝试使用 Tkinter 从 GUI 获取文件名。下面是代码,我在 Windows 上使用 Spyder/Anaconda。该对话框不会显示在任务栏中,并且仅在我最小化 spyder 窗口时才可见。有什么办法可以解决这个问题?
import tkinter, tkinter.filedialog
root = tkinter.Tk()
root.withdraw()
file_path = tkinter.filedialog.askopenfilename(parent=root,title='Pick a file')
【问题讨论】:
-
在 Windows 10 下的 Python 3.6.5 中工作得很好。当 root 被撤回时,对话框不会出现在任务栏中,但是当 root 可见时,对话框不会再次出现在任务栏中。只有root可以。问题可能出在 Spyder/Anaconda 上吗?
-
当我删除
root.withdraw时,会出现根窗口;当我单击它以使其获得焦点时,会出现文件对话框。
标签: python-3.x tkinter spyder