我正试图用以下代码在Sublime text 3中使用python(tkinter)制作一个简单的文本编辑器:
from tkinter import *
from tkinter import filedialog
root=Tk()
def OpenFile():
file_name=filedialog.askopenfilename(initialdir="/Desktop\python", title="Select a File:", filetype=(("Txt Files",".txt"),("All Files","*.*")))
content = open(file_name).read()
txteditor.insert(END, content)
def SaveFile():
myfile = filedialog.asksaveasfile(mode='w', defaultextension='.txt')
if myfile is None:
return
content=txteditor.get(1.0,'end-1c')
myfile.write(content)
root.iconbitmap(default='icon2.ico')
root.title('My Notepad')
txteditor=Text(root, width=50, height=20).pack()
openbtn=Button(root, text='Open', command=OpenFile)
openbtn.pack()
savebtn=Button(root, text='Open', command=OpenFile)
savebtn.pack()
问题在于
\
。python将其解释为转义斜杠-类似于用于\n
交换单\
到\\
的转义斜杠。我知道您提供的错误,您可以看到\
和大写字母。口译员试图避开突出显示的字母相关问题 更多 >
编程相关推荐