Question about asksaveasfilename

Eric Brunel eric.brunel at pragmadev.com
Thu Jun 13 10:40:41 EDT 2002


Mike Callahan wrote:

> I am using asksaveasfilename from tkFileDialog. I want to restrict my
> users to save filenames with these extensions .unl or .sql. This is my
> call:
> 
> from tkFileDialog import asksaveasfilename
> fn = asksaveasfilename(filetypes=[('Unloaded', '*.unl'),
> ('Queries','*.sql')])
> 
> This gives me the correct dialog box, but how do I force the correct
> extension on fn?  Thanks.

There's a defaultextension option, but it does not depend on the selected 
file type, i.e. you'll have to do either:

fn = asksaveasfilename(filetypes=[('Unloaded', '*.unl'),
                                  ('Queries',  '*.sql')],
                       defaultextension='.unl')

or:

fn = asksaveasfilename(filetypes=[('Unloaded', '*.unl'),
                                  ('Queries',  '*.sql')],
                       defaultextension='.sql')

which isn't what you're looking for, I fear...

I don't know any means to force an extension depending on the selecetd file 
type with asksaveasfilename, so my advice would be to split the two save 
options: one "Save unloaded" and one "Save query"... But if there's another 
solution, I'm interested too ;-).

HTH
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com



More information about the Python-list mailing list