import tkinter as tk from tkinter import filedialog class TextEditor: def __init__(self, root): self.root = root self.root.title('Text Editor') self.text = tk.Text(self.root) self.text.pack(fill='both', expand=True) self.create_menu() def create_menu(self): menu = tk.Menu(self.root) self.root.config(menu=menu) file_menu = tk.Menu(menu) menu.add_cascade(label='File', menu=file_menu) file_menu.add_command(label='Open', command=self.open_file) file_menu.add_command(label='Save', command=self.save_file) def open_file(self): file_path = filedialog.askopenfilename(defaultextension='.txt', filetypes=[('Text Files', '*.txt'), ('All Files', '*.*')]) with open(file_path, 'r') as file: self.text.insert('1.0', file.read()) def save_file(self): file_path = filedialog.asksaveasfilename(defaultextension='.txt', filetypes=[('Text Files', '*.txt'), ('All Files', '*.*')]) with open(file_path, 'w') as file: file.write(self.text.get('1.0', 'end')) root = tk.Tk() editor = TextEditor(root) root.mainloop()

Comments

Popular posts from this blog

Best Body building Supplements For Natural Women

Alpine Ice Hack for Weight Loss

Prostadine - New Monster In The Prostate Health Niche