如何使用TKinter添加文件扩展名? [英] How can I add a file extension using TKinter?

查看:296
本文介绍了如何使用TKinter添加文件扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Tkinter将酱菜转储保存到.pkl文件中.我遵循了文档,但是保存文件时没有扩展名.这是一个片段:

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")])

如何制作它,以便如果我将文件命名为hello,那么当用户仅指定文件名时,它将另存为hello.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?

推荐答案

您可以指定defaultextension参数:

filedialog.asksaveasfilename(defaultextension='.pkl')

这篇关于如何使用TKinter添加文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆