I am trying to make a simple text editor with python(tkinter) in Sublime Text 3 with the following code:
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()
but when I click open button, then the window appears but when I click on open button(after selecting the file to be opened), it gives error in line 10