import tkinter as tk
from PIL import Image, ImageTkroot = tk.Tk()
root.geometry("400x400")# Load the GIF file
gif = Image.open(r"C:\Users\Administrator\Desktop\桌面文件\网页图表\轮播图\images\06.gif")# Create a canvas to display the GIF
canvas = tk.Canvas(root, width=400, height=400)
canvas.pack()# Convert the frames of the GIF to PhotoImage for use on the canvas
frames = []
for frame in range(0, gif.n_frames):gif.seek(frame)frames.append(ImageTk.PhotoImage(gif))# Add the frames to the canvas and animate the GIF
def animate_gif(frame=0):canvas.itemconfig(image_item, image=frames[frame])root.after(50, animate_gif, (frame+1) % len(frames))# Add the first frame of the GIF to the canvas
image_item = canvas.create_image(200, 200, image=frames[0])# Start the animation loop
animate_gif()root.mainloop()