【发布时间】:2012-11-23 13:18:38
【问题描述】:
现在我正在使用 Tkinter 提示用户输入文件。
Tk().withdraw() # keep the root window from appearing
file_path = askopenfilename() # show dialog box and return file path
# check if extension is valid
如果用户选择了错误的文件类型,我会用一个新窗口重新提示他们。
有没有办法让同一个 tkinter 窗口保持打开状态,除非选择的文件是有效的?
所以不要这样:
# 1) prompt user to open file
# 2) close file browser window
# 3) check if extension is valid
# 4) if not, print error and re-prompt user with new browser window
我想这样做:
# 1) prompt user to open file
# 2) check if extension is valid while keeping window open
# 3) if not, print error, re-prompting with same window
感谢任何帮助。
【问题讨论】: