面向对象的示例代码,演示使用面向对象的方式处理记事本应用程序中文件菜单的新建、打开、保存和另存为菜单项的点击事件:```pythonfrom tkinter import Tk, Text, Menu, filedialogclass Notepad:def __init__(self):self.root = Tk()self.root.title("记事本")self.text = Text(self.root)self.text.pack()self.create_menu()def create_menu(self):menu_bar = Menu(self.root)self.root.config(menu=menu_bar)file_menu = Menu(menu_bar, tearoff=0)menu_bar.add_cascade(label="文件", menu=file_menu)file_menu.add_command(label="新建", command=self.create_event)file_menu.add_command(label="打开", command=self.open_file)file_menu.add_command(label="保存", command=self.save_file)file_menu.add_command(label="另存为", command=self.save_file)def open_file(self):file_path = filedialog.askopenfilename(filetypes=[("Text files", "*.txt")])if file_path:with open(file_path, "r") as file:content = file.read()self.text.delete("1.0", "end")self.text.insert("1.0", content)