现在我正在使用 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
任何帮助表示赞赏。