在網上看到的,經測試裝有wxpython的,版本為2.7.3的python可用。
# !usr/bin/env python 2.7.3# coding: utf-8# filename: notepad.pyfrom Tkinter import *from ScrolledText import *import tkMessageBoxfrom tkFileDialog import *import fileinputt1=[]root=Nonedef die(): sys.exit(0)def about(): tkMessageBox.showinfo("Tkeditor","V1.0\n" "written in 2012\n" "writer:Test") class editor: def __init__(self,rt): if rt==None: self.t=Tk() else: self.t=Toplevel(rt) self.t.title("Tkeditor %d"%len(t1)) self.bar=Menu(rt) self.filem=Menu(self.bar) self.filem.add_command(label="開啟",command=self.openfile) self.filem.add_command(label="建立",command=neweditor) self.filem.add_command(label="儲存",command=self.savefile) self.filem.add_command(label="關閉",command=self.close) self.filem.add_separator() self.filem.add_command(label="退出",command=die) self.helpm=Menu(self.bar) self.helpm.add_command(label="關於",command=about) self.bar.add_cascade(label="檔案",menu=self.filem) self.bar.add_cascade(label="協助",menu=self.helpm) self.t.config(menu=self.bar) self.f=Frame(self.t,width=512) self.f.pack(expand=1,fill=BOTH) self.st=ScrolledText(self.f,background="white") self.st.pack(side=LEFT,fill=BOTH,expand=1) def close(self): self.t.destroy() def openfile(self): p1=END oname=askopenfilename(filetypes=[("Python file","*.*")]) if oname: for line in fileinput.input(oname): self.st.insert(p1,line) self.t.title(oname) def savefile(self): sname=asksaveasfilename() if sname: ofp=open(sname,"w") ofp.write(self.st.get(1.0,END)) ofp.flush() ofp.close() self.t.title(sname) def neweditor(): global root t1.append(editor(root)) if __name__=="__main__": root=None t1.append(editor(root)) root=t1[0].troot.mainloop()