Skip to content

Commit a5ed478

Browse files
authored
Add files via upload
1 parent 05412d5 commit a5ed478

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Text Editor.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+

0 commit comments

Comments
 (0)