-
Notifications
You must be signed in to change notification settings - Fork 284
/
Notepad.py
66 lines (44 loc) · 1.58 KB
/
Notepad.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
60
61
62
63
64
65
66
from tkinter import *
from tkinter import messagebox,filedialog
root=Tk()
root.title("Notepad")
root.geometry("800x600+100+100")
root.resizable(False,False)
root.config(bg="#48D1CC")
def ope():
op1=filedialog.askopenfile(title="Select File",filetypes=(("Text File",".txt"),))
if op1!=None:
fname.config(text="FILENAME - "+ str(op1.name.split('/')[-1]))
store.set(op1.name)
for i in op1:
area.insert(END,str(i))
op1.close()
def save_as():
op=filedialog.asksaveasfile(title="Save As",filetypes=(("Text File",".txt"),))
op.write(area.get('1.0', END,))
op.close()
messagebox.showinfo("Saved", "File has been saved")
def save():
if store.get()=="":
save_as()
else:
op=open(store.get(),"w")
op.write(area.get('1.0',END,))
op.close()
messagebox.showinfo("Saved", "File has been saved")
File=Menu(root)
file=Menu(File,tearoff=0)
file.add_command(label="Open",command=ope)
file.add_command(label="Save",command=save)
file.add_command(label="Save As",command=save_as)
File.add_cascade(label="File",menu=file)
root.config(menu=File)
buo=Button(root,text="Open",font=("arial",15),command=ope).place(x=20,y=50,width=80)
bus=Button(root,text="Save",font=("arial",15),command=save).place(x=120,y=50,width=80)
busa=Button(root,text="Save As",font=("arial",15),command=save_as).place(x=220,y=50,width=80)
store=StringVar()
fname=Label(root,text="FILENAME",font=("arial",20))
fname.place(x=20,y=100)
area=Text(root,font=("times new roman",15))
area.place(x=20,y=150,width=600,height=390)
root.mainloop()