adjust the gui grid so that it has 3 columns (0, 1 , 2) and 2 rows (0, 1). Add a spacer frame that is in column 1 and row 1. the sidebar should be column 0 and cover both row 0 and 1. The header should be column 1 and 2 and row 0. And the table should be column 2 and row 2. Python code: def setup_ui(self):
"""Set up the user interface."""
# Configure root grid: two columns (sidebar and main content)
self.root.grid_rowconfigure(0, weight=1)
self.root.grid_columnconfigure(1, weight=1) # column 1 for main content

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 delete table sections."""
# Sidebar Frame
sidebar = self._create_frame(
parent=self.root,
width=self.sidebar_width,
bg=self.sidebar_color
)
sidebar.grid(row=0, column=0, sticky='ns')
sidebar.grid_propagate(False)
sidebar.columnconfigure(0, weight=1)
sidebar.rowconfigure(0, weight=1) # Functional sidebar
# No spacer row
# sidebar.rowconfigure(1, minsize=10) # Spacer (Removed)

# Functional sidebar content
functional_sidebar = self._create_frame(
    parent=sidebar,
    width=self.sidebar_width,
    bg=self.sidebar_color
)
functional_sidebar.grid(row=0, column=0, sticky='nsew')
functional_sidebar.columnconfigure(0, weight=1)
functional_sidebar.rowconfigure(0, weight=0)  # normal_buttons_frame
functional_sidebar.rowconfigure(1, weight=1)  # scrollable_canvas_frame
functional_sidebar.rowconfigure(2, weight=0)  # delete_table_section

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: Optional[int],
bg: str
) -> tk.Frame:
"""Create a frame with specified width and background."""
frame = tk.Frame(parent, width=width, bg=bg, bd=0, relief='flat')
if width:
frame.config(width=width)
return frame

def _add_normal_buttons(self, sidebar: tk.Frame):
"""Add buttons to the sidebar."""
normal_buttons_frame = self._create_frame(
parent=sidebar,
width=self.sidebar_width,
bg=self.sidebar_color
)
normal_buttons_frame.grid(row=0, column=0, sticky='ew', padx=10, pady=(10, 0))
normal_buttons_frame.columnconfigure(0, weight=1)

create_table_label = self._create_clickable_label(
    parent=normal_buttons_frame,
    text="Create New Table",
    command=self.create_new_table,
    anchor='center'
)
create_table_label.grid(row=0, column=0, pady=10, sticky='ew')
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(
parent=sidebar,
width=self.sidebar_width,
bg=self.sidebar_color
)
scrollbar_frame.grid(row=1, column=0, sticky='nsew', padx=10, pady=10)
scrollbar_frame.columnconfigure(0, weight=1)
scrollbar_frame.rowconfigure(0, weight=1)

canvas = tk.Canvas(
    scrollbar_frame,
    bg=self.sidebar_color,
    highlightthickness=0
)
canvas.grid(row=0, column=0, sticky='nsew')

self.config_scrollbar_style()

scrollbar = ttk.Scrollbar(
    scrollbar_frame,
    orient="vertical",
    command=canvas.yview,
    style="Custom.Vertical.TScrollbar"
)
scrollbar.grid(row=0, column=1, sticky='ns')

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")

# Bind mouse wheel for scrolling
canvas.bind("<MouseWheel>", lambda event: canvas.yview_scroll(int(-1 * (event.delta / 120)), "units"))

# Configure scroll region when content changes
self.table_labels_frame.bind("<Configure>", lambda event: canvas.configure(scrollregion=canvas.bbox("all")))
scrollbar_frame.bind("<Configure>", lambda event: self._update_scrollbar(scrollbar_frame, canvas, scrollbar))

def _update_scrollbar(self, scrollbar_frame, canvas, scrollbar):
"""Update scrollbar visibility based on content size."""
canvas.update_idletasks()
canvas_height = scrollbar_frame.winfo_height()
content_height = self.table_labels_frame.winfo_reqheight()

if content_height > canvas_height:
    scrollbar.grid()  # Ensure scrollbar is visible
    canvas.configure(yscrollcommand=scrollbar.set)
    canvas.bind("<MouseWheel>", lambda event: canvas.yview_scroll(int(-1 * (event.delta / 120)), "units"))
else:
    scrollbar.grid_remove()  # Hide scrollbar if not needed
    canvas.configure(yscrollcommand=lambda *args: None)
    canvas.unbind("<MouseWheel>")

def _add_delete_table_section(self, sidebar: tk.Frame):
"""Add delete table option to the sidebar."""
delete_table_frame = self._create_frame(
parent=sidebar,
width=self.sidebar_width,
bg=self.sidebar_color
)
delete_table_frame.grid(row=2, column=0, sticky='ew', padx=10, pady=(0, 10))
delete_table_frame.columnconfigure(0, weight=1)

delete_table_label = self._create_clickable_label(
    parent=delete_table_frame,
    text="🗑 Delete Selected Table",
    command=self.delete_table,
    anchor='center'
)
delete_table_label.grid(row=0, column=0, pady=10, sticky='ew')
self.add_custom_hover(delete_table_label)

def _add_separator(self, parent: tk.Widget):
"""Add a horizontal separator."""
separator = ttk.Separator(parent, orient='horizontal')
separator.grid(row=1, column=0, sticky='ew', pady=5)

def _create_clickable_label(
self,
parent: tk.Widget,
text: str,
command,
allow_rename: bool = False,
anchor: str = 'w'
) -> tk.Label:
"""Create a clickable label with optional rename functionality."""
cursor = "arrow" if allow_rename else "hand2"
label = tk.Label(
parent,
text=text,
bg=self.button_color,
fg=self.text_color,
cursor=cursor,
anchor=anchor
)
label.bind("", lambda _: command())
if allow_rename:
label.bind("", lambda _: self.begin_rename(text))
return label

def create_main_frame(self):
"""Create the main frame."""
self.main_frame = tk.Frame(self.root, bg=self.background_color)
self.main_frame.grid(row=0, column=1, sticky='nsew')
self.main_frame.grid_rowconfigure(1, weight=1) # table_frame expands
self.main_frame.grid_columnconfigure(0, weight=1)

def create_header_frame(self):
"""Create the header with filter and settings options."""
header_frame = self._create_frame(
parent=self.main_frame,
width=None,
bg=self.background_color
)
header_frame.grid(row=0, column=0, sticky='ew')
header_frame.config(height=self.header_height)
header_frame.grid_propagate(False)
header_frame.grid_columnconfigure(1, weight=1)
header_frame.grid_columnconfigure(2, weight=0)

tk.Label(
    header_frame,
    text="Filter:",
    bg=self.background_color,
    fg=self.text_color
).grid(row=0, column=0, padx=10, pady=10, sticky='w')

self.filter_entry = tk.Entry(
    header_frame,
    fg=self.text_color
)
self.filter_entry.grid(row=0, column=1, padx=(0, 10), pady=10, sticky='ew')
self.filter_entry.bind("<KeyRelease>", lambda _: self.apply_filter())

settings_label = tk.Label(
    header_frame,
    text="...",
    bg=self.background_color,
    fg=self.text_color,
    cursor="hand2",
    anchor='e'
)
settings_label.grid(row=0, column=2, padx=10, pady=10, sticky='e')

# The parent for the menu should be root or header_frame
settings_menu = tk.Menu(self.root, 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)

settings_label.bind("<Button-1>", lambda e: settings_menu.post(e.x_root, e.y_root))
settings_label.bind("<Enter>", lambda _: settings_label.config(bg=self.button_color_selected))
settings_label.bind("<Leave>", lambda _: settings_label.config(bg=self.background_color))

def create_table_frame(self):
"""Create the table frame."""
self.table_frame = tk.Frame(
self.main_frame,
bg=self.background_color
)
self.table_frame.grid(row=1, column=0, sticky='nsew')
self.table_frame.grid_rowconfigure(0, weight=1)
self.table_frame.grid_columnconfigure(0, weight=1)