Right now I am using Tkinter to prompt the user for a file.
Tk().withdraw() # keep the root window from appearing
file_path = askopenfilename() # show dialog box and return file path
# check if extension is valid
If the user selected the wrong file type, I re-prompt them with a new window.
Is there a way, instead, to keep the same tkinter window open unless the file selected is valid?
so instead of this:
# 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
I want to do this:
# 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
Any help is appreciated.
If you want the user to open a particular file type, use the
filetypesargument. It takes a list of file type definitions, which you specify as a description and an extension: