How can I add a file extension using TKinter?

2019-08-22 16:17发布

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?

1条回答
趁早两清
2楼-- · 2019-08-22 16:45

You can specify defaultextension parameter:

filedialog.asksaveasfilename(defaultextension='.pkl')
查看更多
登录 后发表回答