-
Notifications
You must be signed in to change notification settings - Fork 0
/
Notepad.py
45 lines (36 loc) · 1.46 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
import tkinter as tk
from tkinter.constants import END
from tkinter.filedialog import askopenfilename , asksaveasfilename
def saving_file():
file_location = asksaveasfilename(
defaultextension="txt" ,
filetypes = [("Text Files","*.txt"),["All files ","*.*"]])
if not file_location:
return
with open(file_location,"w") as file_output:
text = text_edit.get(1.0,tk.END)
file_output.write(text)
root.title(f"MY OWN NOTEPAD - {file_location}")
def opening_file():
file_location = askopenfilename(
filetypes = [("Text Files","*.txt"),("All files","*.*")])
if not file_location:
return
text_edit.delete(1.0,tk.END)
with open(file_location , "r") as file_input:
text = file_input.read()
text_edit.insert(tk.END,text)
root.title(f"MY OWN NOTEPAD - { file_location}")
root=tk.Tk()
root.title("Notepad")
root.rowconfigure(0,minsize=800)
root.columnconfigure(1,minsize=800)
text_edit = tk.Text(root) #text is a function
text_edit.grid(row=0 , column=1 ,sticky="nsew")
frame_button = tk.Frame(root , relief = tk.RAISED , bd=3)
frame_button.grid(row=0,column=0,sticky="nsew")
button_open = tk.Button(frame_button,text="OPEN FILE" ,command = opening_file)
button_open.grid(row=0,column=0,padx=5,pady=5)
button_save = tk.Button(frame_button,text="SAVE AS" ,command= saving_file)
button_save.grid(row=1,column=0 ,padx=5)
root.mainloop()