-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTEXTEDITOR.py
More file actions
39 lines (31 loc) · 1.24 KB
/
TEXTEDITOR.py
File metadata and controls
39 lines (31 loc) · 1.24 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
import tkinter as tk
from tkinter import filedialog, messagebox
def new_file():
text.delete(1.0, tk.END)
def open_file():
file_path = filedialog.askopenfilename(defaultextension=".txt", filetypes=[("Text Files","*.txt")])
if file_path:
with open(file_path,'r') as file:
text.delete(1.0,tk.END)
text.insert(tk.END, file.read())
def save_file():
file_path = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text Files","*.txt")])
if file_path:
with open(file_path, 'w') as file:
file.write(text.get(1.0 , tk.END))
messagebox.showinfo("info", "File saved ")
root = tk.Tk()
root.title("Simple Text Editor")
root.geometry("900x700")
menu = tk.Menu(root)
root.config(menu=menu)
file_menu= tk.Menu(menu)
menu.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="New" , command=new_file)
file_menu.add_command(label="Open" , command=open_file)
file_menu.add_command(label="Save", command=save_file)
file_menu.add_separator()
file_menu.add_command(label="Exit",command=root.quit)
text = tk.Text(root , wrap=tk.WORD , font=("",12,), fg="blue", )
text.pack(expand=tk.YES, fill=tk.BOTH)
root.mainloop()