Skip to content

Commit 29c5691

Browse files
committed
feat: Added notepad basic program
1 parent 1fe58df commit 29c5691

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Notepad/main.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from tkinter import *
2+
from tkinter import filedialog, messagebox
3+
4+
root = Tk()
5+
root.geometry("700x500")
6+
root.title("Aman's Notepad")
7+
8+
def save_file():
9+
open_file = filedialog.asksaveasfile(mode='w', defaultextension=".txt")
10+
if open_file is None:
11+
return
12+
text = str(entry.get(1.0, END))
13+
open_file.write(text)
14+
open_file.close()
15+
16+
def clear():
17+
messagebox.showinfo("Cleared", "Cleared all contents !")
18+
entry.delete(1.0, END)
19+
20+
def open_file():
21+
file = filedialog.askopenfile(mode='r', filetype=[('text files', '*.txt')])
22+
if file is not None:
23+
content = file.read()
24+
entry.insert(INSERT, content)
25+
26+
b1 = Button(root, text="Save", command=save_file)
27+
b1.place(x=10, y=10)
28+
29+
b2 = Button(root, text="Clear", command=clear)
30+
b2.place(x=70, y=10)
31+
32+
b3 = Button(root, text="Open", command=open_file)
33+
b3.place(x=120, y=10)
34+
35+
entry = Text(root, height=60, width=70, wrap=WORD, bg="black", fg="green", selectbackground="red",
36+
font="Courier 15", insertbackground="violet")
37+
entry.place(x=10, y=50)
38+
39+
root.mainloop()

0 commit comments

Comments
 (0)