import tkinter as tk
from tkinter import filedialog, colorchooser, Menu, font as tkFont
from tkinter import ttk

class TextEditor:
    def __init__(self, root):
        self.root = root
        self.root.title("bogdan Notepad")
        self.root.geometry("800x600")

        # Set default font
        self.font_family = "Arial"  # Starting with a printed font
        self.font_size = 12

        # Create a Notebook (tabbed interface)
        self.notebook = ttk.Notebook(self.root)
        self.notebook.pack(expand=True, fill=tk.BOTH)
        self.notebook.bind("<<NotebookTabChanged>>", self.on_tab_changed)  # Bind tab change event

        # Create a menu
        self.create_menu()

    def create_menu(self):
        menu_bar = Menu(self.root)

        # File menu
        file_menu = Menu(menu_bar, tearoff=0)
        file_menu.add_command(label="New Tab", command=self.new_file)
        file_menu.add_command(label="Open", command=self.open_file)
        file_menu.add_command(label="Save", command=self.save_file)
        file_menu.add_command(label="Save As", command=self.save_as)
        file_menu.add_separator()
        file_menu.add_command(label="Exit", command=self.exit_app)
        menu_bar.add_cascade(label="File", menu=file_menu)

        # Edit menu
        edit_menu = Menu(menu_bar, tearoff=0)
        edit_menu.add_command(label="Undo", command=self.undo_action)
        edit_menu.add_command(label="Redo", command=self.redo_action)
        edit_menu.add_separator()
        edit_menu.add_command(label="Cut", command=self.cut_text)
        edit_menu.add_command(label="Copy", command=self.copy_text)
        edit_menu.add_command(label="Paste", command=self.paste_text)
        menu_bar.add_cascade(label="Edit", menu=edit_menu)

        # Format menu
        format_menu = Menu(menu_bar, tearoff=0)
        format_menu.add_command(label="Normal", command=self.set_normal)
        format_menu.add_command(label="Bold", command=self.toggle_bold)
        format_menu.add_command(label="Italic", command=self.toggle_italic)
        format_menu.add_command(label="Text Color", command=self.change_text_color)
        format_menu.add_separator()
        format_menu.add_command(label="Printed Font", command=self.set_printed_font)
        format_menu.add_command(label="Lowercase", command=self.convert_to_lowercase)
        format_menu.add_command(label="Upper Case", command=self.convert_to_uppercase)
        menu_bar.add_cascade(label="Format", menu=format_menu)

        # Configure the menu
        self.root.config(menu=menu_bar)

    def new_file(self):
        frame = ttk.Frame(self.notebook)
        self.notebook.add(frame, text="Untitled")
        text_area = tk.Text(frame, wrap=tk.WORD, bg="white", fg="black", insertbackground="black", undo=True)
        text_area.pack(expand=True, fill=tk.BOTH)

        # Create and display a close button (X) on the right side
        close_button = tk.Button(frame, text="X", command=lambda tab_id=self.notebook.tabs()[1]: self.close_tab(tab_id))  # Pass tab ID
        close_button.pack(side=tk.RIGHT)

        text_area.config(font=tkFont.Font(family=self.font_family, size=self.font_size))

    def open_file(self):
        # ... rest of the code for opening files ...

    # ... rest of the code for other functions ...

    def close_tab(self, tab_id):
        self.notebook.forget(tab_id)

    def on_tab_changed(self, event):
        # Update the font and other settings when a tab is selected
        current_tab = self.notebook.select()
        text_area = self.get_current_text_widget(current_tab)
        if text_area:
            text_area.config(font=tkFont.Font(family=self.font_family, size=self.font_size))

if __name__ == "__main__":
    root = tk.Tk()
    editor = TextEditor(root)
    root.mainloop()
scrie codul complet