Refactor the following python 3.12 code. It is a setup of the ui of a larger codebase. Focus on readability and unnecessary complexity. Use modern python features where appropriate. Python 3.12 code:     def setup_ui(self):
        """Set up the user interface."""
        self.create_sidebar()
        self.create_main_frame()
        self.create_header_frame()
        self.create_table_frame()

    def create_sidebar(self):
        """Create the sidebar with functional and spacer frames."""
        functional_sidebar = self._create_frame(self.root, self.sidebar_width, self.sidebar_color, 'left', 'nw', 'y')
        spacer_frame = self._create_frame(self.root, self.static_frame_width, self.background_color, 'left', 'nw', 'y')
    
        functional_sidebar.pack_propagate(False)
        self._add_normal_buttons(functional_sidebar)
        self._add_scrollable_canvas(functional_sidebar)
        self._add_delete_table_section(functional_sidebar)

    def _create_frame(self, parent: tk.Widget, width: int | None, bg: str, side: str, anchor: str, fill: str, expand: bool = False) -> tk.Frame:
        """Create and pack a frame."""
        frame = tk.Frame(parent, width=width, bg=bg, bd=0, relief='flat')
        frame.pack(side=side, anchor=anchor, fill=fill, expand=expand)
        return frame

    def _add_normal_buttons(self, sidebar: tk.Frame):
        """Add buttons to sidebar."""
        normal_buttons_frame = self._create_frame(sidebar, None, self.sidebar_color, 'top', 'nw', 'x')
        create_table_label = self._create_clickable_label(normal_buttons_frame, "Create New Table", self.create_new_table, 'center')
        create_table_label.pack(pady=10, anchor='center')
        self.add_custom_hover(create_table_label)
        self._add_separator(normal_buttons_frame)

    def _add_scrollable_canvas(self, sidebar: tk.Frame):
        """Add scrollable canvas for table labels."""
        scrollbar_frame = self._create_frame(sidebar, None, self.sidebar_color, 'top', 'nw', 'both', True)
        canvas = tk.Canvas(scrollbar_frame, bg=self.sidebar_color, highlightthickness=0, width=self.sidebar_width - 15)
        canvas.pack(side="left", fill="both", expand=True)
        self.config_scrollbar_style()
        scrollbar = ttk.Scrollbar(scrollbar_frame, orient="vertical", command=canvas.yview, style="Custom.Vertical.TScrollbar")
        scrollbar.pack(side="right", fill="y")
        canvas.configure(yscrollcommand=scrollbar.set)
        self.table_labels_frame = tk.Frame(canvas, bg=self.sidebar_color)
        canvas.create_window((0, 0), window=self.table_labels_frame, anchor="nw")
    
        canvas.bind_all("<MouseWheel>", lambda event: canvas.yview_scroll(int(-1*(event.delta/120)), "units"))
    
        self._bind_scrollbar_events(canvas, scrollbar, scrollbar_frame)

    def _bind_scrollbar_events(self, canvas: tk.Canvas, scrollbar: ttk.Scrollbar, scrollbar_frame: tk.Frame):
        """Manage scrollbar visibility."""
        def configure_scrollbar(event: tk.Event | None = None):
            canvas.update_idletasks()
            canvas_height = scrollbar_frame.winfo_height()
            content_height = self.table_labels_frame.winfo_reqheight()
            
            if content_height > canvas_height:
                scrollbar.pack(side="right", fill="y")
                canvas.bind_all("<MouseWheel>", lambda event: canvas.yview_scroll(int(-1*(event.delta/120)), "units"))
            else:
                scrollbar.pack_forget()
                canvas.unbind_all("<MouseWheel>")
    
            canvas.configure(scrollregion=canvas.bbox("all"))
    
        self.table_labels_frame.bind("<Configure>", configure_scrollbar)
        scrollbar_frame.bind("<Configure>", configure_scrollbar)
    
    def _add_delete_table_section(self, sidebar: tk.Frame):
        """Add delete table option."""
        self._add_separator(sidebar)
        delete_table_label = self._create_clickable_label(sidebar, "🗑 Delete Selected Table", self.delete_table)
        delete_table_label.pack(side='bottom', anchor='center', pady=10)
        self.add_custom_hover(delete_table_label)

    def _add_separator(self, parent: tk.Widget):
        """Add horizontal separator."""
        separator = ttk.Separator(parent, orient='horizontal')
        separator.pack(fill='x')

    def _create_clickable_label(self, parent: tk.Widget, text: str, command, allow_rename: bool = False, anchor: str = 'w') -> tk.Label:
        """Create clickable label."""
        label = tk.Label(parent, text=text, bg=self.button_color, fg=self.text_color, cursor="hand2" if not allow_rename else "arrow", anchor=anchor)
        label.bind("<Button-1>", lambda event: command())
        if allow_rename:
            label.bind("<Double-1>", lambda event: self.begin_rename(text))
        return label

    def create_main_frame(self):
        """Create main frame."""
        self.main_frame = tk.Frame(self.root)
        self.main_frame.pack(expand=True, fill='both', side='right')

    def create_header_frame(self):
        """Create header with filter and settings."""
        header_frame = tk.Frame(self.main_frame, height=self.header_height, bg=self.background_color)
        header_frame.pack(fill='x')
        header_frame.pack_propagate(False)
        tk.Label(header_frame, text="Filter:", bg=self.background_color, fg=self.text_color).pack(side='left')
        self.filter_entry = tk.Entry(header_frame, fg=self.text_color)
        self.filter_entry.pack(side='left')
        self.filter_entry.bind("<KeyRelease>", lambda event: self.apply_filter())
        settings_label = tk.Label(header_frame, text="...", bg=self.background_color, fg=self.text_color, cursor="hand2", anchor='w')
        settings_label.place(relx=1.0, rely=0.0, anchor='ne', x=-40, y=20)
        settings_menu = tk.Menu(settings_label, tearoff=0)
        settings_menu.add_command(label="Export Table", command=self.export_table)
        settings_menu.add_command(label="Import Table", command=self.import_file)
        settings_menu.add_command(label="Rename Headers", command=self.rename_headers)

        def show_settings_menu(event):
            settings_menu.post(event.x_root, event.y_root)

        settings_label.bind("<Button-1>", show_settings_menu)

        def on_enter_settings(event):
            settings_label.config(bg=self.button_color_selected)

        def on_leave_settings(event):
            settings_label.config(bg=self.background_color)

        settings_label.bind("<Enter>", on_enter_settings)
        settings_label.bind("<Leave>", on_leave_settings)

    def create_table_frame(self):
        """Create table frame."""
        self.table_frame = tk.Frame(self.main_frame, bg=self.background_color)
        self.table_frame.pack(expand=True, fill='both')