-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
35 lines (27 loc) · 1021 Bytes
/
main.py
File metadata and controls
35 lines (27 loc) · 1021 Bytes
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
import tkinter as tk
from tkinter import filedialog
def open_file():
file_path = filedialog.askopenfilename(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(filetypes=[("Text files", "*.txt")])
if file_path:
with open(file_path, 'w') as file:
file.write(text.get("1.0", tk.END))
root = tk.Tk()
root.title("Text Editor")
root.geometry("800x600")
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="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)
text.pack(expand=tk.YES, fill=tk.BOTH)
root.mainloop()