-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotepad.py
More file actions
92 lines (74 loc) · 2.62 KB
/
notepad.py
File metadata and controls
92 lines (74 loc) · 2.62 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import tkinter
from tkinter.constants import BOTH, END, RIGHT, Y
import tkinter.messagebox
import tkinter.filedialog,os
if __name__ == '__main__':
root=tkinter.Tk()
root.title("Notepad")
def cut():
text.event_generate("<<Cut>>")
def copy():
text.event_generate("<<Copy>>")
def paste():
text.event_generate("<<Paste>>")
def about():
tkinter.messagebox.showinfo("Notepad","Notepad by Aviney")
def newfile():
global file
root.title("Untitled-Notepad")
file=None
text.delete(1.0,END)
def openfile():
global file
file= tkinter.filedialog.askopenfilename(defaultextension=".txt",filetypes=[("All Files","*.*"),("Text Documents","*.txt")])
if (file is ""):
file=None
else:
root.title(os.path.basename(file) + "-Notepad")
text.delete(1.0,END)
data=open(file,"r")
text.insert(1.0,data.read())
data.close()
def savefile():
global file
if (file==None):
file= tkinter.filedialog.asksaveasfilename(initialfile="Untitled.txt",defaultextension=".txt",filetypes=[("All Files","*.*"),("Text Documents","*.txt")])
if (file is ""):
file=None
else:
datad=open(file,"w")
datad.write(text.get(1.0, END))
datad.close()
root.title(os.path.basename(file) + "-Notepad")
else:
datad=open(file,"w")
datad.write(text.get(1.0, END))
datad.close()
def quitApp():
root.destroy()
scroll=tkinter.Scrollbar(root)
scroll.pack(fill=Y,side=RIGHT)
root.geometry("644x788")
file=None
text=tkinter.Text(root,font="lucida 13",yscrollcommand=scroll.set)
text.pack(fill=BOTH,expand=True)
scroll.config(command=text.yview)
#menu
menu=tkinter.Menu(root)
m1=tkinter.Menu(menu,tearoff=0)
m1.add_command(label="New",command=newfile)
m1.add_command(label="Open",command=openfile)
m1.add_command(label="Save",command=savefile)
m1.add_separator()
m1.add_command(label="Exit",command=quitApp)
menu.add_cascade(menu=m1,label="File")
m2=tkinter.Menu(menu,tearoff=0)
m2.add_command(label="Cut",command=cut)
m2.add_command(label="Copy",command=copy)
m2.add_command(label="Paste",command=paste)
menu.add_cascade(menu=m2,label="Edit")
m3=tkinter.Menu(menu,tearoff=0)
m3.add_command(label="About Notepad",command=about)
menu.add_cascade(menu=m3,label="Help")
root.config(menu=menu)
root.mainloop()