import tkinter as tk
# Create the main window
window = tk.Tk()
window.title("Simple Text Editor")
# Create a text widget
text_widget = tk.Text(window, wrap=tk.WORD, bg="white")
text_widget.pack()
# Create a menu bar
menu_bar = tk.Menu(window)
# Create a file menu
file_menu = tk.Menu(menu_bar, tearoff=0)
file_menu.add_command(label="New", command=new_doc)
file_menu.add_command(label="Open", command=open_doc)
file_menu.add_command(label="Save", command=save_doc)
file_menu.add_command(label="Exit", command=window.destroy)
# Create an edit menu
edit_menu = tk.Menu(menu_bar, tearoff=0)
edit_menu.add_command(label="Cut", command=text_widget.cut)
edit_menu.add_command(label="Copy", command=text_widget.copy)
edit_menu.add_command(label="Paste", command=text_widget.paste)
# Create a help menu
help_menu = tk.Menu(menu_bar, tearoff=0)
help_menu.add_command(label="About", command=lambda: tk.message_dialog(window, title="About", message="This is a simple text editor written in Python using the Tkinter library."))
# Add the menus to the window
window.config(menu=menu_bar)
# Define the functions for the menu commands
def new_doc():
# Clear the text widget
text_widget.delete("1.0", tk.END)
def open_doc():
# Prompt the user to open a file
file_path = tk.file_askopenfilename()
if file_path:
# Open the file and display its contents in the text widget
with open(file_path, "r") as f:
text_widget.insert(tk.END, f