Python based on the TK text editor

Source: Internet
Author: User

1 #Coding=utf-82 ImportSys,os3 ImportTkfiledialog4  fromTkinterImport*5  fromTkfontImportFont6 7 8 Print "You are Welcome to use the Editor:", str (sys.argv[0]) [:-3]9 Ten classWrite (): One  A     def __init__(self): -self.tk=Tk () -          ifLen (sys.argv[0]) >=2: theFname=self.fname=sys.argv[1] -          Else: -Fname=self.fname='New.txt' - Self.createui (fname) + Self.tk.mainloop () -  +  A     defCreateui (self,fname): at          #Create Menu -Menubar=menu (self.tk,bg='Purple') -Fmenu=menu (menubar,tearoff=0) -Fmenu.add_command (label='Open', command=Self.open) -Fmenu.add_command (label='Save', command=self.save) -Fmenu.add_command (label='Exit', command=exit) inMenubar.add_cascade (label="File", menu=Fmenu) -Self.tk.title ("Welcome to writer!") toSelf.tk.geometry ("800x600") +Self.tk.config (menu=menubar,background="Gray", BorderWidth = 8) -          #L = theSelf.txt=text (Width=6000,height=6000,font=font (self.tk,size=14)) * With Open (fname) as F: $Content =F.read ()Panax Notoginseng f.close () -              Printcontent theFilecontent=content +          #Self.txt.delete (1.0,end) A Self.txt.insert (insert,filecontent) the Self.txt.pack () +  -     defSave (self): $Txtcontent = Self.txt.get (1.0, END) $Self.savefile (content=txtcontent) -  -  the     defOpen (self): -Self.filename = tkfiledialog.askopenfilename (Initialdir =os.getcwd ())WuyiFilecontent=self.openfile (fname=self.filename) the          ifFilecontent is  not-1: -Self.text.delete (1.0, END) WuSelf.text.insert (1.0, Filecontent) -  About     defOpenFile (self,fname=None): $          ifFName isNone: -               return-1 -Self.fname =fname -File = Open (fname,'r+') AContent =File.read () + file.close () the          returncontent -  $     defSaveFile (self,content=None): the          ifContent isNone: the               return-1 theFile=open (Self.fname,'W') the file.write (content) - File.flush () in file.close () the          return0 the  About     defexit (self): the sys.exit (0) the  the if __name__=='__main__': +     ifLen (SYS.ARGV) >=2: - Write () the     Else:Bayi         Print "Please add the name of the file you want to edit, for example: Python%s new.txt"%SYS.ARGV[0]
writer.py

Python based on the TK text editor

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.