0

so I'm using the 'initialfile' to automatically generate the name of the import file,
but I'm using 'defaultextension' to set the extension when clicking 'Save'

how do I set the 'defaultextension' based on the current filter selection??

2
Contributors
2
Replies
7
Views
6 Years
Discussion Span
Last Post by Tcll
2
# the Tkinter filedialog for saving file
# tkfd.asksaveasfile(**options) returns file handle to save to

try:
    # Python2
    import Tkinter as tk
    import tkFileDialog as tkfd
except ImportError:
    # Python3
    import tkinter as tk
    import tkinter.filedialog as tkfd

mask = [
    ("Text files","*.txt"),
    ("Python files","*.py *.pyw"),
    ("All files","*.*")]

# if the filename does not have extension
# it will add the specified defaultextension
file_save = "test77"
fout = tkfd.asksaveasfile(
    title="testing defaultextension='.txt'",
    initialdir="C:/Python27/Atest27/Bull",
    initialfile=file_save,
    defaultextension=".txt",
    filetypes=mask)

# test write a file
data = """\
1
2
3
4
"""
fout.write(data)
fout.close()
Votes + Comments
good post
helpful stuff
0

well WTF D:<

I'm using this:

exfl = asksaveasfilename(
    initialfile=str((str(imfl).split("/")[-1]).split('.')[0]),
    filetypes=ex_types,
    defaultextension='.obj') #small bug (you have to type the extension before saving)

ex_types is a generated list returned from the plugins...
but it's returnng the types as it should...

and yours works
but yet mine doesn't D:

Edited by Tcll: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.