-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project.py
38 lines (29 loc) · 1.15 KB
/
Project.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
import tkinter as tk
from tkinter import filedialog
def open_file():
file_path = filedialog.askopenfilename()
if file_path:
with open(file_path, 'r') as file:
text_area.delete(1.0, tk.END)
text_area.insert(tk.END, file.read())
def save_file():
file_path = filedialog.asksaveasfilename(defaultextension=".txt",
filetypes=[("Text files", "*.txt"), ("All files", "*.*")])
if file_path:
with open(file_path, 'w') as file:
file.write(text_area.get(1.0, tk.END))
root = tk.Tk()
root.title("Simple Text Editor")
text_area = tk.Text(root)
text_area.pack(fill='both', expand=True, padx=16, pady=16)
menu = tk.Menu(root)
root.config(menu=menu)
file_menu = tk.Menu(menu, tearoff=0)
menu.add_cascade(label="File", menu=file_menu)
# Styling the "File" menu button
file_menu.configure(font=("Arial", 12, "bold"), foreground="whitesmoke", background="lightgray")
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)
root.mainloop()