-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbasic_text_editor.py
59 lines (37 loc) · 1.43 KB
/
basic_text_editor.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from Tkinter import *
class Editor:
def __init__(self, master):
global text_box
text_box = Text(root)
text_box.pack()
text_box.focus_set()
def contents():
contents = text.get(1.0, END)
print contents
def load(path):
user_file = open(path, 'r')
text = str(user_file.read())
print text
text_box.delete(1.0, END)
text_box.insert(END, text)
user_file.close()
def save(path):
user_file = open(path, 'w')
contents = text_box.get(1.0, END)
user_file.write(contents)
user_file.close()
print contents
path = Entry(master)
path.pack(side=RIGHT)
path.insert(0, 'text_file.txt')
load(path.get())
save_b = Button(root, text="save", width=10, command = lambda: save(path.get()))#command=save(path.get()))
load_b = Button(root, text="load", width=10, command = lambda: load(path.get()))#command=load(path.get()))
get_b = Button(root, text="get", width=10, command=contents)
load_b.pack(side=LEFT)
save_b.pack(side=LEFT)
get_b.pack(side=LEFT)
root = Tk()
root.wm_title("Luke's Text Editor")
app = Editor(root)
root.mainloop()