A simple Notepad program

Source: Internet
Author: User

We can see on the Internet that wxpython is installed and Python 2.7.3 is available.

# !usr/bin/env python 2.7.3
# coding: utf-8
# filename: notepad.py
from Tkinter import *
from ScrolledText import *
import tkMessageBox
from tkFileDialog import *
import fileinput
T1=[]
Root=None
Def 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 = "open", command = self. OpenFile)
Self.filem.add_command (label = "new", command = neweditor)
Self.filem.add_command (label = "save", command = self. Savefile)
Self.filem.add_command (label = "close", command = self. Close)
self.filem.add_separator()
Self.filem.add_command (label = "exit", command = die)
self.helpm=Menu(self.bar)
Self.helpm.add_command (label = "about", command = about)
Self.bar.add ˊ cascade (label = "file", menu = self. Filem)
Self. Bar. Add ˊ cascade (label = "help", 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].t
root.mainloop() 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.