<s>[INST] import tkinter as tk
from tkinter import filedialog
from PIL import Image, ImageTk
import os

# Create root window
root = tk.Tk()

# Create frame for images
frame = tk.Frame(root)
frame.pack()

# Create buttons and labels
open_button = tk.Button(root, text="Open", command=lambda: open_image())
open_button.pack()

def open_image():
    file = filedialog.askopenfilename()
    if file:
        image = Image.open(file)
        image.thumbnail((800, 800)) # Resize the image
        photo = ImageTk.PhotoImage(image)
        image_label = tk.Label(frame, image=photo)
        image_label.image = photo # to prevent garbage collection
        image_label.pack()

# Start the program
root.mainloop()

This script opens an image file and displays the resized image on the window.

However, if I try to load another image using the "Open" button, the previous image is not removed from the window.

How can I modify the script so that when a new image is loaded, it replaces the previous one?[/INST]