-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotepad.py
More file actions
47 lines (34 loc) · 1.26 KB
/
Notepad.py
File metadata and controls
47 lines (34 loc) · 1.26 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
from tkinter import WORD, BOTH, END, INSERT
from tkinter.filedialog import *
import tkinter as tk
def saveFile():
new_file = asksaveasfile(mode = "w", filetype = [('text file', '.txt')])
if new_file is None:
return
text = str(entry.get(1.0, END))
new_file.write(text)
new_file.close()
def openFile():
file = askopenfile(mode="r", filetype = [('text file', '*.txt')])
if file is not None:
content = file.read()
entry.insert(INSERT, content)
def clearFile():
entry.delete(1.0, END)
canvas = tk.Tk()
canvas.geometry("400x600")
canvas.title("Notepad")
canvas.config(bg = "white")
top = tk.Frame(canvas)
top.pack(padx = 10, anchor = 'nw', pady = 5 )
b1 = tk.Button(canvas, text = "Open", bg = "white", command = openFile)
b1.pack(in_ = top, side = "left")
b2 = tk.Button(canvas, text = "Save", bg = "white", command = saveFile)
b2.pack(in_ = top, side = "left")
b3 = tk.Button(canvas, text = "Clear", bg = "white", command = clearFile)
b3.pack(in_ = top, side = "left")
b4 = tk.Button(canvas, text = "Exit", bg = "white", command = exit)
b4.pack(in_ = top, side = "left")
entry = tk.Text(canvas, wrap = WORD, bg = "#F9DDA4", font =("poppins", 15))
entry.pack(padx = 15, pady = 5, expand = True, fill = BOTH)
canvas.mainloop()