Modify the code so that new entries are saved automatically. Code: import tkinter as tk
from tkinter import ttk, messagebox
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()  # Ensure to fetch data for SELECT queries
        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)
    
    for row in run_query('SELECT * FROM movies'):
        movies_tree.insert('', 'end', values=row[1:])
    
    for row in run_query('SELECT * FROM series'):
        series_tree.insert('', 'end', values=row[1:])

def add_entry(tree, columns):
    tree.insert('', 'end', values=[''] * len(columns))

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 movie = ? AND year = ?", (new_value, values[0], values[1]))
    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
    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 show_movies():
    series_frame.forget()
    movies_frame.pack(fill='both', expand=True)

def show_series():
    movies_frame.forget()
    series_frame.pack(fill='both', expand=True)

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

create_tables()

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)

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('<Double-1>', 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('<Double-1>', lambda e: edit_cell(e, series_tree))

load_data()

btn_frame = ttk.Frame(root)
btn_frame.pack(pady=10, fill='x', expand=False)

add_movie_btn = ttk.Button(btn_frame, text="Add Movie", command=lambda: add_entry(movies_tree, movies_columns))
add_series_btn = ttk.Button(btn_frame, text="Add Series", command=lambda: add_entry(series_tree, series_columns))
save_btn = ttk.Button(btn_frame, text="Save Data")

show_movies()

root.mainloop()