2013-02-16 38 views
4

背景如何讓Windows自動爲文件添加擴展名?

我目前在獲得Tkinter的一個基本的瞭解,希望做一個基本的文本編輯器的過程。我想製作我自己的文件格式,名稱爲.mydoc我試圖將filetype更改爲.mydoc以無效爲準。這是我目前擁有的代碼:

代碼

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) 

問題

  1. 我怎麼可以讓電腦自動添加我的擴展? (是的,我已經關閉了hide extensions選項

技術規格

語言:Python的2.7.3

操作系統:Windows 7

+0

什麼是具體的錯誤信息或症狀? – engineerC 2013-02-16 14:31:00

+0

@CaptainMurphy問題是,沒有錯誤信息。我保存文件,當我進入Windows資源管理器時,它沒有擴展名。 – xxmbabanexx 2013-02-16 14:47:20

回答

3

嘗試使用defaultextension

tkF.askopenfilename(initialdir='D:\\', 
filetypes=myFormat, 
title="Open a .mydoc", 
defaultextension=".mydoc") 
相關問題