so,my question is How to make a custom file extension for your Tkinter program python i also searched in on youtube but the program ask from which program you want to open the file and I don't want it can you give me the answer to that
1 Answer
You can try this:
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()
In file you can write preety much anything. .digital, .kid, .anything.
1 Comment
Matiiss
I strongly advise against using wildcard (
*) when importing something, You should either import what You need, e.g. from module import Class1, func_1, var_2 and so on or import the whole module: import module then You can also use an alias: import module as md or sth like that, the point is that don't import everything unless You actually know what You are doing; name clashes are the issue.
.pyfile, correct? well that won't work (unless you specify how to open it somehow by default and stuff), well you otherwise have two options: open the file usingcmdand then type:python file_name.pyor convert your file to an executable (.exe) file and then it will run as any other executable file on windows (or the according file depending on your OS).xyz,.digitalpreety much anything but if you want to open that extension(file) with some specific program. The that is big deal. You may look here. I think this will solve your issue.