python - Restricting the file extension saved when using tkFileDialog.asksaveasfile -
i writing gui in python using tkinter user able save state of gui in directory extension ".espace".
filename = tkfiledialog.asksaveasfilename(defaultextension=".espace")
if user specifies different file extension file saved extension specified. there anyway prevent this? restricted saving file extension ".espace"?
thanks in advance.
you can specify file type using 'filetypes' option. below example change file type drop down on save dialog .espace , files.
filename = tkfiledialog.asksaveasfilename(defaultextension=".espace", filetypes=(("espace file", "*.espace"),("all files", "*.*") )) i have not found option, using asksaveasfilename, restrict use of other file extensions. i'd think write loop force user use extension:
import os import sys ext = "" while ext != ".escape": filename = tkfiledialog.asksaveasfilename(defaultextension=".espace", filetypes=(("espace file", "*.espace"),("all files", "*.*") )) file,ext = os.path.splitext(filename)
Comments
Post a Comment