-
Notifications
You must be signed in to change notification settings - Fork 0
/
textEditor.py
40 lines (32 loc) · 1.02 KB
/
textEditor.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
from tkinter import *
from tkinter.filedialog import *
filename = None
def saveAs():
f = asksaveasfile(mode='w', defaultextension='.txt')
t = text.get(0.0, END)
try:
f.write(t.rstrip())
except:
# showerror(title="Oops!", message="Unable to save file...")
exit
def openFile():
f = askopenfile(mode='r')
t = f.read()
text.delete(0.0, END)
text.insert(0.0, t)
root = Tk()
root.title("My Python Text Editor")
root.minsize(width=400, height=400)
root.maxsize(width=400, height=400)
text = Text(root, width=400, height=400)
text.pack()
menubar = Menu(root)
filemenu = Menu(menubar)
# filemenu.add_command(label="New", command=newFile)
filemenu.add_command(label="Open", command=openFile)
# filemenu.add_command(label="Save", command=saveFile)
filemenu.add_command(label="Save As...", command=saveAs)
filemenu.add_command(label="Quit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
root.config(menu=menubar)
root.mainloop()