import tkinter as tk from tkinter import filedialog,messagebox def save_file(): file_path = filedialog.asksaveasfilename(defaultextension=".txt") if file_path: with open(file_path, "w") as file: file.write(text.get("1.0", tk.END)) root = tk.Tk() root.title("Notepad") text = tk.Text(root) text.pack(expand=True, fill="both") menubar = tk.Menu(root) filemenu = tk.Menu(menubar, tearoff=0) filemenu.add_command(label="Save", command=save_file) filemenu.add_separator() filemenu.add_command(label="Exit", command=root.quit) menubar.add_cascade(label="File", menu=filemenu) root.config(menu=menubar) root.mainloop()