Python GUI text editor

Written in Python using a simple text editor, need to show a user interface, features include open, save the text file.

Use tkinter library to write GUI.

 1 #简单GUI文本编辑器
 2 from tkinter import *
 3 from tkinter.scrolledtext import ScrolledText 
 4 
 5 def load():
 6     with open(filename.get()) as file:
 7         contents.delete('1.0', END) 
 8         contents.insert(INSERT, file.read()) 
 9 
10 def save():
11     with open(filename.get(), 'w') as file:
12         file.write(contents.get('1.0', END)) 
13 
14 top = Tk() 
15 top. title("Simple Editor"16 
17 contents = ScrolledText() 
18 contents.pack(side=BOTTOM, expand=True, fill=BOTH) 
19 
20 filename = Entry() 
21 filename.pack(side=LEFT, expand=True, fill=X) 
22 
23 Button(text='Open', command=load).pack(side=LEFT) 
24 Button(text='Save', command=save).pack(side=LEFT) 
25 
26 mainloop() 

 

Guess you like

Origin www.cnblogs.com/nonoo/p/11618397.html