1

About python tkinter.filedialog I tried to set the file extension type, but no matter what I did,asksaveasfilename does not return the file type ,that is why? It is a bug in tkinter?

from tkinter import *
from tkinter.filedialog import *
root=Tk()
root.geometry('500x500')
path=asksaveasfilename(filetypes=(('Txt file','.txt'),('Python file','.py')))
print(path)
root.mainloop()

the result :

C:\Users\acer\Desktop\python>pythonfile

It has no extension type

Davis Herring
  • 36,443
  • 4
  • 48
  • 76
i am cat
  • 31
  • 4

1 Answers1

0

The problem seems to be your path variable. You need to set the defaultextension option like so:

path=asksaveasfilename(defaultextension="*.*", filetypes=(('Txt file','.txt'), ('Python file','.py')))
temp123
  • 362
  • 1
  • 4