How can I add a file extension using TKinter?

我怕爱的太早我们不能终老 提交于 2019-12-11 15:17:16

问题


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:


You can specify defaultextension parameter:

filedialog.asksaveasfilename(defaultextension='.pkl')


来源:https://stackoverflow.com/questions/46517738/how-can-i-add-a-file-extension-using-tkinter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!