import tkinter
import tkinter.messagebox
import tkinter.scrolledtext
import tkinter.filedialog
from tkinter import *
filename=''
def openfun():
global filename
filename=tkinter.filedialog.askopenfilename(title='打开文件')
if filename=='':
return
txt=open(filename,'r').read().encode('gb2312').decode('gb2312')
txtContent.insert(END,txt)
filename=''
def savefun():
pass
def saveasfun():
pass
def cutfun():
pass
def pastefun():
pass
def copyfun():
pass
def aboutfun():
tkinter.messagebox.showinfo(title='关于',message='作者:周伟明')
win=tkinter.Tk()
win.title('简单文本编辑器')
win['width']=600
win['height']=420
menu=tk.Menu(win)
submenu1=tkinter.Menu(menu,tearoff=0)
menu.add_cascade(label='文件',menu=submenu1)
submenu1.add_command(label='打开文件',command=openfun)
submenu1.add_command(label='保存文件',command=savefun)
submenu1.add_command(label='另存为',command=saveasfun)
submenu1.add_separator()
submenu1.add_command(label='退出',command=aboutfun)
submenu2=tkinter.Menu(menu,tearoff=0)
menu.add_cascade(label='编辑',menu=submenu2)
submenu2.add_command(label='剪切',command=cutfun)
submenu2.add_command(label='复制',command=copyfun)
submenu2.add_command(label='粘贴',command=pastefun)
submenu3=tkinter.Menu(menu,tearoff=0)
menu.add_cascade(label='帮助',menu=submenu3)
submenu3.add_command(label='关于',command=aboutfun)
win.config(menu=menu)
txtContent=tkinter.scrolledtext.ScrolledText(win,wrap=tkinter.WORD)
txtContent.pack(fill=tkinter.BOTH,expand=tkinter.YES)
win.mainloop()