I am using tkFileDialog.asksaveasfilename function in a GUI. The following is the code:
def onSaveImage(self):
ftypes = [('PNG', '*.png'), ('JPEG', '*.jpg'), ('PDF', '*.pdf')]
imagefname = tkFileDialog.asksaveasfilename(parent=self, filetypes = ftypes)
The function to save the file is deduced from the filename extension. Is there a more elegant way to get the users choice of file type from the file dialog itself?
Maybe now it's late but Try to set defaultextension
saveDirectory=asksaveasfilename(defaultextension=".*",filetypes = (("JPEG files","*.jpg"),('all files','*.*')))
you'll get the result is the filename following by the the users choice of file type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With