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:
.mydoc
filetype
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
hide extensions
Specifications
Language: Python 2.7.3
OS: Windows 7
Try using defaultextension :
defaultextension
tkF.askopenfilename(initialdir='D:\\', filetypes=myFormat, title="Open a .mydoc", defaultextension=".mydoc")