Fix this Traceback (most recent call last):   File "D:\cookie monster\DeepAscension Video2Image+.7z-20241113T104527Z-001\video.py", line 100, in <module>     root.protocol("WM_DELETE_WINDOW", on_closing) NameError: name 'root' is not defined here is code import ttkbootstrap as tb
from ttkbootstrap.constants import *
from tkinter import filedialog, messagebox  # Updated import
import os
import subprocess
import threading
import concurrent.futures
import queue
import psutil
import sys

# ... [rest of the imports and initializations] ...

def on_closing():
    """Handle window closing to ensure all threads are properly terminated."""
    if messagebox.askokcancel("Quit", "Do you want to quit?"):
        stop_all_event.set()
        root.destroy()

def select_input_folders():
    """Allow user to select multiple input folders."""
    while True:
        folder = filedialog.askdirectory(title="Select Input Folder (Cancel to finish)")
        if folder:
            if folder not in input_folders and folder not in input_videos:
                input_folders.append(folder)
                tree.insert('', 'end', iid=folder, values=(folder, "Folder", "Pending"))
            else:
                messagebox.showwarning("Duplicate Entry", f"The entry '{folder}' is already selected.")
        else:
            break

def select_input_videos():
    """Allow user to select multiple video files."""
    files = filedialog.askopenfilenames(title="Select Video Files",
                                        filetypes=[("Video Files", "*.mp4 *.avi *.mov *.mkv *.flv *.wmv")])
    for file in files:
        if file not in input_videos and file not in input_folders:
            input_videos.append(file)
            tree.insert('', 'end', iid=file, values=(file, "Video File", "Pending"))
        else:
            messagebox.showwarning("Duplicate Entry", f"The file '{file}' is already selected.")

def process_videos():
    """Main function to process videos and folders."""
    # ... [existing code] ...
    if not input_folders and not input_videos:
        messagebox.showerror("Error", "Please select at least one input folder or video file.")
        set_buttons_state(NORMAL)
        return
    if not output_folder:
        messagebox.showerror("Error", "Please select an output folder.")
        set_buttons_state(NORMAL)
        return
    # ... [rest of the code] ...

def set_disk_threshold():
    """Set the disk space threshold for auto-pausing."""
    try:
        value = int(disk_threshold_entry.get())
        if value <= 0:
            raise ValueError
        global disk_space_threshold_mb
        disk_space_threshold_mb = value
        messagebox.showinfo("Threshold Set", f"Auto-pause threshold set to {value} MB.")
    except ValueError:
        messagebox.showerror("Invalid Input", "Please enter a valid positive integer for the disk space threshold.")

def finalize_processing():
    """Finalize the processing by updating the UI and displaying any errors."""
    set_buttons_state(NORMAL)
    if errors:
        error_message = "\n\n".join(errors)
        messagebox.showerror("Processing Completed with Errors", error_message)
    else:
        messagebox.showinfo("Success", "All videos have been successfully processed.")
    progress_bar['value'] = 0
    status_label.config(text="Processing completed.")

def monitor_disk_space():
    """Monitor disk space and auto-pause if below threshold."""
    if stop_all_event.is_set():
        return

    output_path = output_folder_var.get() or '/'
    try:
        total, used, free = psutil.disk_usage(output_path)
        if free < disk_space_threshold_mb * 1024 * 1024:
            if not is_paused:
                on_pause()
                messagebox.showwarning("Auto-Pause", "Disk space below threshold. Processing has been paused.")
    except Exception as e:
        messagebox.showerror("Disk Space Error", f"Unable to determine disk space for '{output_path}'.\nError: {e}")
    if not stop_all_event.is_set():
        root.after(DISK_CHECK_INTERVAL, monitor_disk_space)

# ... [rest of the code] ...

# Handle window closing to ensure all threads are properly terminated
root.protocol("WM_DELETE_WINDOW", on_closing)

# Run the GUI loop
root.mainloop()