tk显示gif动态图

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()


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部