[英]How to make a custom file extension for your tkinter program python
所以,我的問題是如何為您的 Tkinter 程序 python 創建自定義文件擴展名那
你可以試試這個:
from tkinter.filedialog import asksaveasfile
from tkinter import *
base = Tk()
def SaveFile():
data = [('All tyes(*.*)', '*.*'),(<Show it to user>,<actual extension>)]
file = asksaveasfilename(filetypes = data, defaultextension = data)
# file will have file name provided by user.
# Now we can use this file name to save file.
with open(file,"w") as f:
f.write(<data you want to save>)
save_btn = Button(base, text = 'Click to save file ', command = SaveFile)
save_btn.pack(side = TOP, pady = 20,padx = 50)
base.mainloop()
在file
你可以寫任何東西。 .digital
、 .kid
、 .anything
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.