-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotepad.py
More file actions
61 lines (50 loc) · 1.81 KB
/
notepad.py
File metadata and controls
61 lines (50 loc) · 1.81 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
from tkinter import *
from tkinter import messagebox
from tkinter import filedialog
from PIL import ImageTk, Image
import os
root=Tk()
root.minsize(650,650)
root.maxsize(650,650)
open_img= ImageTk.PhotoImage(Image.open ("open.png"))
save_img= ImageTk.PhotoImage(Image.open ("save.png"))
exit_img= ImageTk.PhotoImage(Image.open ("exit.jpg"))
L_file_name= Label(root, text= "File Name =")
L_file_name.place(relx=0.45,rely=0.04,anchor= CENTER)
input_file= Entry(root)
input_file.place(relx=0.60,rely=0.04,anchor= CENTER)
text_area= Text(root, height= 34, width=80)
text_area.place(relx=0.5,rely=0.5,anchor= CENTER)
name=""
def open_file():
global name
input_file.delete(0, END)
text_area.delete(1.0, END)
text_file= filedialog.askopenfilename(title= " Open Your File",filetypes=(("Text Files","*.txt"),))
print(text_file)
name= os.path.basename(text_file)
edited_name= name.split(".")[0]
root.title(edited_name)
input_file.insert(0, edited_name)
text_file= open(name,"r")
entire_file= text_file.read()
text_area.insert(END, entire_file)
text_file.close()
def save():
input_name= input_file.get()
file= open(input_name + ".txt" , "w")
text= text_area.get("1.0" , END)
print(text)
file.write(text)
input_file.delete(0, END)
text_area.delete(1.0 ,END)
messagebox.showinfo("Updated" , "Success")
def exit_window():
root.destroy()
button_open= Button(root, image= open_img , command= open_file)
button_open.place(relx=0.12,rely=0.04 , anchor= CENTER)
button_save=Button(root,image=save_img,command=save)
button_save.place(relx=0.06,rely=0.04,anchor= CENTER)
button_exit= Button(root, image=exit_img, command= exit_window)
button_exit.place(relx=0.18,rely=0.04, anchor= CENTER)
root.mainloop()