File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ # Text Editor
2+
3+ This porgram is a GUI text editor which now just has simple functions:
4+
5+ - Edit texts, save it and open it with its name.
6+
7+ It was originally the code of ` Beginning Python From Novice to Professional(Third Edtion) ` ,and I hope to improve it in with deeper study of Python.
8+
9+ ``` python
10+ from tkinter import *
11+ from tkinter.scrolledtext import ScrolledText
12+
13+ def load ():
14+ with open (filename.get()) as file :
15+ contents.delete(' 1.0' , END )
16+ contents.insert(INSERT , file .read())
17+
18+ def save ():
19+ with open (filename.get(), ' w' ) as file :
20+ file .write(contents.get(' 1.0' , END ))
21+
22+ top = Tk()
23+ top.title(" Simple Editor" )
24+
25+ contents = ScrolledText()
26+ contents.pack(side = BOTTOM , expand = True , fill = BOTH )
27+
28+ filename = Entry()
29+ filename.pack(side = LEFT , epand = True , fill = BOTH )
30+
31+ Button(text = ' Open' , command = load).pack(side = LEFT )
32+ Button(text = ' Save' , command = save).pack(side = LEFT )
33+
34+ mainloop()
35+ ```
36+
37+ ![ image-20210305205215072] (/Users/wocaibujiaoquanmei/Library/Application Support/typora-user-images/image-20210305205215072.png)
38+
You can’t perform that action at this time.
0 commit comments