0

I am trying to save a pickle dump to a .pkl file using Tkinter. I followed the documentation but when I save the file it has no extension. This is a snippet:

root = tk.Tk()
root.withdraw()
messagebox.showinfo("Select Save Location", "Please save the Feature list")
Tk().withdraw()
savedf = filedialog.asksaveasfilename(filetypes=[("Pickle Dumps","*.pkl")])

How do I make it so that if I name the file hello it will save as hello.pkl when the user only specifies the file name?

2
  • You probably have to type the filename including the extension into the "ask filename" dialog. Commented Oct 1, 2017 at 23:13
  • Oh I wanted to make it so the user only has to specify the file name not the extension Commented Oct 1, 2017 at 23:14

1 Answer 1

1

You can specify defaultextension parameter:

filedialog.asksaveasfilename(defaultextension='.pkl')
Sign up to request clarification or add additional context in comments.

1 Comment

Except on MacOsx, defaultextension='' causes the first extension of the current filetype to be copied. This is useful when one has multiple file types, as with IDLE save-as ((.py, .pyw), .txt).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.