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??

# 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()
commented: helpful stuff +4
commented: good post +14

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:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.