Python 简单的记事本,Python简单记事本,这个程序只实现了最基本的
Python 简单的记事本,Python简单记事本,这个程序只实现了最基本的
这个程序只实现了最基本的编辑、保存、打开和新建的功能,用了几个简单的Tkinter组件
# _*_ coding: utf-8 _*_from 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()#该片段来自于http://byrx.net
相关内容
- Python 简单的计算器,Python简单计算器,Python完成的一个
- 把整数转为二进制,整数转为二进制,把整数转为二进制
- Python 版的 PinkTrace 示例 pink-fork-linux.py,,#!/usr/bin/e
- Py4J 示例代码 (Python 调用 Java API),py4jpython,这段代码
- 对文件进行编码转换,文件进行编码转换,import sysim
- 将 HTML 文件转成指定的编码,html编码,import sysim
- 加载二进制文件到 CkByteArray 对象,二进制ckbytearray,im
- 在字节数组中搜索 findBytes,数组findbytes,import chilk
- removeChunk - remove a subrange from a byte array.,,Remove a chu
- pad and unpad byte array,padunpad,Demonstrates
评论关闭