Tkinter File Dialog Question

Jørgen Cederberg jorgencederberg at hotmail.com
Mon Nov 4 02:14:25 EST 2002


"Steve Zatz" <slzatz at hotmail.com> wrote in message news:6747bc9d.0211021953.4fd02462 at posting.google.com...
> In the Tkinter FileSaveAs Dialog - is there any way to get at the
> user's selection of a file extension?  If the user creates a file
> without an extension, I want to append the "Save as type" extension
> (what it's called under Windows), but I don't see any way to get at
> the dialog box's value for the file extension.  Any help would be
> appreciated.

Hi Steve,

you can use the option: 'defaultextension'. Example

>>> import tkFileDialog
>>> res = tkFileDialog.asksaveasfilename(defaultextension=".txt")
(user types in "myfilename")
>>> res
'myfilename.txt'

Remember the dot in the extension string. I just tried and it works, unless the user selects a filename that already exist.

Regards
Jorgen Cederberg





More information about the Python-list mailing list