GUI文本编辑器

简介

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# coding:utf-8

from tkinter import *
from tkinter.scrolledtext import ScrolledText

def load():
with open(filename.get())as file:
contents.delete('1.0',END)
contents.insert(INSERT,file.read())

def save():
with open(filename.get(),'w')as file:
file.write(contents.get('1.0',END))

top = Tk()
top.title('Simple Editor')

contents = ScrolledText()
contents.pack(side=BOTTOM,expand=True,fill=BOTH)
contents_2 = ScrolledText() # constens_2 没有关联上方法,所以没有用
contents_2.pack(side=BOTTOM,expand=True,fill=BOTH)

filename = Entry()
filename.pack(side=LEFT,expand=True,fill=BOTH)
filename_2 = Entry() # filename_2 没有关联上方法,所以没有用
filename_2.pack(side=LEFT,expand=True,fill=BOTH)

Button(text='Open',command=load).pack(side=LEFT)
Button(text='Save',command=save).pack(side=LEFT)

mainloop()