Tkinter GIF 动画摇摇欲坠且像素化
Tkinter GIF Animation falters and is pixelated
我在 After Effects 中制作了加载轮动画,我正尝试在 python 中将其与 tkinter 一起使用。虽然动画是每秒 60 帧,但它不稳定并且不会显示整个帧。这是我的代码:
from tkinter import *
from PIL import Image
root = Tk()
root.geometry("1920x1080")
image1 = Image.open("LoadingWheel.gif")
framesTotal = image1.n_frames
animation = [PhotoImage(file="LoadingWheel.gif", format=f'gif -index {i}') for i in range(framesTotal)]
def update(ind):
frame = animation[ind]
label.configure(image=frame)
ind += 1
if ind == framesTotal:
ind = 0
root.after(60, update, ind)
label = Label(root)
label.pack()
root.after(0, update, 0)
root.mainloop()
第一张图片是我 运行 脚本时的截图,第二张图片是它应该的样子!
我希望有人知道如何解决这个问题!
提前致谢!
使用ImageTk.PhotoImage
from tkinter import *
from PIL import Image, ImageTk
root = Tk()
#root.geometry("1920x1080")
image1 = Image.open(r"loading.gif")
framesTotal = image1.n_frames
play_back_delay = 30
animation = []
def loadGif():
for x in range(framesTotal):
frame = ImageTk.PhotoImage(image1.copy())
animation.append(frame)
image1.seek(x)
def update(ind):
frame = animation[ind]
label.configure(image=frame)
ind += 1
if ind == framesTotal:
ind = 0
root.after(play_back_delay, update, ind)
label = Label(root)
label.pack()
loadGif()
update(0)
root.mainloop()
我在 After Effects 中制作了加载轮动画,我正尝试在 python 中将其与 tkinter 一起使用。虽然动画是每秒 60 帧,但它不稳定并且不会显示整个帧。这是我的代码:
from tkinter import *
from PIL import Image
root = Tk()
root.geometry("1920x1080")
image1 = Image.open("LoadingWheel.gif")
framesTotal = image1.n_frames
animation = [PhotoImage(file="LoadingWheel.gif", format=f'gif -index {i}') for i in range(framesTotal)]
def update(ind):
frame = animation[ind]
label.configure(image=frame)
ind += 1
if ind == framesTotal:
ind = 0
root.after(60, update, ind)
label = Label(root)
label.pack()
root.after(0, update, 0)
root.mainloop()
第一张图片是我 运行 脚本时的截图,第二张图片是它应该的样子!
我希望有人知道如何解决这个问题!
提前致谢!
使用ImageTk.PhotoImage
from tkinter import *
from PIL import Image, ImageTk
root = Tk()
#root.geometry("1920x1080")
image1 = Image.open(r"loading.gif")
framesTotal = image1.n_frames
play_back_delay = 30
animation = []
def loadGif():
for x in range(framesTotal):
frame = ImageTk.PhotoImage(image1.copy())
animation.append(frame)
image1.seek(x)
def update(ind):
frame = animation[ind]
label.configure(image=frame)
ind += 1
if ind == framesTotal:
ind = 0
root.after(play_back_delay, update, ind)
label = Label(root)
label.pack()
loadGif()
update(0)
root.mainloop()