一個簡單的記事本程式

來源:互聯網
上載者:User

在網上看到的,經測試裝有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()
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.