Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file type from the "asksaveasfilename" function

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?

like image 320
tmartin Avatar asked Aug 03 '26 18:08

tmartin


1 Answers

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

like image 65
Bowber Avatar answered Aug 06 '26 09:08

Bowber