Refactor the code to use pyside6 instead of tkinter. Print the new code in full. Think step by step. Code: import tkinter as tk
from tkinter import ttk
import sqlite3

def run_query(query, parameters=()):
with sqlite3.connect('media.db') as conn:
cursor = conn.cursor()
result = cursor.execute(query, parameters)
if query.strip().lower().startswith("select"):
return result.fetchall()
conn.commit()

def create_tables():
create_movies_table_sql = '''
CREATE TABLE IF NOT EXISTS movies (
id INTEGER PRIMARY KEY AUTOINCREMENT,
movie TEXT,
year INTEGER,
present BOOLEAN,
watched BOOLEAN,
notes TEXT
);
'''
create_series_table_sql = '''
CREATE TABLE IF NOT EXISTS series (
id INTEGER PRIMARY KEY AUTOINCREMENT,
series TEXT,
seasons TEXT,
year TEXT,
present BOOLEAN,
seasons_present TEXT,
complete BOOLEAN,
watched BOOLEAN,
seasons_seen TEXT,
notes TEXT
);
'''
run_query(create_movies_table_sql)
run_query(create_series_table_sql)

def load_data():
for row in movies_tree.get_children():
movies_tree.delete(row)
for row in series_tree.get_children():
series_tree.delete(row)

# Load data into the movies treeview
movies_data = run_query('SELECT * FROM movies')
if not movies_data:
    # Adding an empty row if the table is empty
    run_query("INSERT INTO movies (movie, year, present, watched, notes) VALUES (?, ?, ?, ?, ?)", ('', None, None, None, ''))
    movies_data = run_query('SELECT * FROM movies')

for row in movies_data:
    movies_tree.insert('', 'end', iid=row[0], values=row[1:])

# Load data into the series treeview
series_data = run_query('SELECT * FROM series')
if not series_data:
    # Adding an empty row if the table is empty
    run_query("INSERT INTO series (series, seasons, year, present, seasons_present, complete, watched, seasons_seen, notes) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
              ('', '', '', None, '', None, None, '', ''))
    series_data = run_query('SELECT * FROM series')

for row in series_data:
    series_tree.insert('', 'end', iid=row[0], values=row[1:])

def add_entry(tree):
if tree == movies_tree:
run_query("INSERT INTO movies (movie, year, present, watched, notes) VALUES (?, ?, ?, ?, ?)", ('', None, None, None, ''))
elif tree == series_tree:
run_query("INSERT INTO series (series, seasons, year, present, seasons_present, complete, watched, seasons_seen, notes) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", ('', '', '', None, '', None, None, '', ''))

load_data()

def delete_entry(tree, item):
if not tree.exists(item):
print(f"Item {item} not found in tree.")
return
item_values = tree.item(item, "values")
if tree == movies_tree:
run_query("DELETE FROM movies WHERE id = ?", (item,))
elif tree == series_tree:
run_query("DELETE FROM series WHERE id = ?", (item,))
load_data()

def save_edit(tree, item, col, new_value):
tree.set(item, column=col, value=new_value)

if tree == movies_tree:
    columns = ["movie", "year", "present", "watched", "notes"]
    values = movies_tree.item(item, 'values')
    run_query(f"UPDATE movies SET {columns[col]} = ? WHERE id = ?", (new_value, item))
elif tree == series_tree:
    columns = ["series", "seasons", "year", "present", "seasons_present", "complete", "watched", "seasons_seen", "notes"]
    values = series_tree.item(item, 'values')
    run_query(f"UPDATE series SET {columns[col]} = ? WHERE series = ? AND year = ?", (new_value, values[0], values[2]))

def edit_cell(event, tree):
selected_item = tree.selection()
if not selected_item:
return
selected_item = selected_item[0]
col = tree.identify_column(event.x)[1:]
if col.isdigit():
col = int(col) - 1

def on_edit_complete(event=None):
    new_value = entry_var.get()
    save_edit(tree, selected_item, col, new_value)
    entry.destroy()

x, y, width, height = tree.bbox(selected_item, column=f'#{col + 1}')

entry_var = tk.StringVar()
entry = tk.Entry(tree, textvariable=entry_var, width=int(width / 7))
entry_var.set(tree.item(selected_item, 'values')[col])
entry.place(x=x, y=y, anchor='nw', height=height, width=width)
entry.focus_set()
entry.bind("<Return>", on_edit_complete)
entry.bind("<FocusOut>", on_edit_complete)

def on_hover(event, widget, bg_color):
widget.config(bg=bg_color)

def show_buttons(event, tree, plus_button, minus_button):
item = tree.identify_row(event.y)
if item:
bbox = tree.bbox(item)
if bbox:
plus_button.place(x=2, y=bbox[1], width=20, height=bbox[3])
minus_button.place(x=24, y=bbox[1], width=20, height=bbox[3])

        plus_button.bind("<Button-1>", lambda e: add_entry(tree))
        minus_button.bind("<Button-1>", lambda e, i=item: delete_entry(tree, i))

        # Hover effects
        plus_button.bind("<Enter>", lambda e: on_hover(e, plus_button, "lightgray"))
        plus_button.bind("<Leave>", lambda e: on_hover(e, plus_button, "white"))
        minus_button.bind("<Enter>", lambda e: on_hover(e, minus_button, "lightgray"))
        minus_button.bind("<Leave>", lambda e: on_hover(e, minus_button, "white"))

def hide_buttons(event, plus_button, minus_button):
plus_button.place_forget()
minus_button.place_forget()

def enter_empty_bar(event, tree, plus_button, minus_button):
show_buttons(event, tree, plus_button, minus_button)

def leave_empty_bar(event, plus_button, minus_button):
hide_buttons(event, plus_button, minus_button)

def show_movies():
series_frame.pack_forget()
movies_frame.pack(expand=True, fill='both')
empty_frame.bind("", lambda event: enter_empty_bar(event, movies_tree, plus_button, minus_button))
empty_frame.bind("", lambda event: leave_empty_bar(event, plus_button, minus_button))
empty_frame.bind("", lambda event: show_buttons(event, movies_tree, plus_button, minus_button))
empty_frame.pack(expand=False, fill='y', side='left')

def show_series():
movies_frame.pack_forget()
series_frame.pack(expand=True, fill='both')
empty_frame.bind("", lambda event: enter_empty_bar(event, series_tree, plus_button, minus_button))
empty_frame.bind("", lambda event: leave_empty_bar(event, plus_button, minus_button))
empty_frame.bind("", lambda event: show_buttons(event, series_tree, plus_button, minus_button))
empty_frame.pack(expand=False, fill='y', side='left')

root = tk.Tk()
root.title("Movies and Series Tracker")

create_tables()
Sidebar with buttons

sidebar_frame = tk.Frame(root, width=100, bg='lightgray')
sidebar_frame.pack(side='left', fill='y')

movies_button = tk.Button(sidebar_frame, text="Movies", command=show_movies)
movies_button.pack(fill='x', padx=5, pady=5)

series_button = tk.Button(sidebar_frame, text="Series", command=show_series)
series_button.pack(fill='x', padx=5, pady=5)
Increase the width of the empty frame for spacing and plus/minus buttons

empty_frame = tk.Frame(root, width=50, bg='white')
empty_frame.pack(expand=False, fill='y', side='left')
Main content frame

content_frame = tk.Frame(root)
content_frame.pack(side='right', fill='both', expand=True)

movies_frame = tk.Frame(content_frame)
series_frame = tk.Frame(content_frame)

movies_columns = ("Movie", "Year", "Present", "Watched", "Notes")
movies_tree = ttk.Treeview(movies_frame, columns=movies_columns, show='headings')
for column in movies_columns:
movies_tree.heading(column, text=column)
movies_tree.column(column, anchor='center')
movies_tree.pack(expand=True, fill='both')
movies_tree.bind('', lambda e: edit_cell(e, movies_tree))

series_columns = ("Series", "Seasons", "Year", "Present", "Seasons Present", "Complete", "Watched", "Seasons (Seen)", "Notes")
series_tree = ttk.Treeview(series_frame, columns=series_columns, show='headings')
for column in series_columns:
series_tree.heading(column, text=column)
series_tree.column(column, anchor='center')
series_tree.pack(expand=True, fill='both')
series_tree.bind('', lambda e: edit_cell(e, series_tree))
Plus and minus buttons with hover effects

plus_button = tk.Label(empty_frame, text="+", bg="white", fg="black", font=("Arial", 12), cursor="hand2")
minus_button = tk.Label(empty_frame, text="-", bg="white", fg="black", font=("Arial", 12), cursor="hand2")

load_data()

show_movies()

root.mainloop()