How to force windows to automatically add an extension to a file?

Background

I am currently creating a basic text editor in the hope of gaining a basic understanding of Tkinter. I want to create my own file format called .mydoc . I tried changing filetype to .mydoc so as not to prevail. This is the code I currently have:

code

 def openMe(self): #import the Tk file dialogue import tkFileDialog as tkF myFormat = [('Example Format', '*.mydoc')] direct = tkF.askopenfilename(initialdir='D:\\', filetypes = myFormat, title = "Open a .mydoc") try: #open the text file txt_file = open(direct,"r") except UnboundLocalError, IOError: print "You either did not select a file, or the filetype was incorrect.\nPlease try again." #Read the data currentTEXT = txt_file.read() #Delete current text self.write.delete(0.0, END) #insert new text self.write.insert(0.0, currentTEXT) 

Question

  • How can I automatically add my extension to my computer? (And yes, I disabled the hide extensions option.

Specifications

Language: Python 2.7.3

OS: Windows 7

+4
source share
1 answer

Try using defaultextension :

 tkF.askopenfilename(initialdir='D:\\', filetypes=myFormat, title="Open a .mydoc", defaultextension=".mydoc") 
+3
source

All Articles