-
Notifications
You must be signed in to change notification settings - Fork 0
/
notepad.py
42 lines (30 loc) · 1.07 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
from tkinter import *
from tkinter import filedialog
def save_file():
open_file = filedialog.asksaveasfile(mode='w',defaultextension=".txt")
if open_file is None:
return
text=str(entry.get(1.0,END))
open_file.write(text)
open_file.close()
def clear():
entry.delete(1.0,END)
def load():
file=filedialog.askopenfile(mode="r",filetype=[('text files','*.txt')])
if file is not None:
content= file.read()
entry.insert(INSERT,content)
root = Tk()s
root.geometry("500x600")
root.title("Text Editor")
root.config(bg="SkyBlue2")
root.resizable(False,False)
savebtn = Button(root,text="Save file",command=lambda:save_file(),bg="RoyalBlue1" )
savebtn.place(x=10,y=10,width="120")
clearbtn = Button(root,text="Clear",command=lambda:clear(),bg="RoyalBlue1")
clearbtn.place(x=150,y=10,width="120")
loadbtn = Button(root,text="Load File",command=lambda:load(),bg="RoyalBlue1")
loadbtn.place(x=290,y=10 ,width="120")
entry = Text(root,height=33,width=58,wrap=WORD)
entry.place(x=10, y=50)
root.mainloop()