I am having an issue with my code and am relatively new to using the PIL library. My code works, however the GIF is extremely bad quality and i'm not exactly sure how to fix it. My code is below:
import tkinter
from tkinter import *
from PIL import Image, ImageTk
window = tkinter.Tk()
window.title("****** Interface")
window.configure(background="white")
# Photo
class MyLabel(tkinter.Label):
def __init__(self, master, filename):
im = Image.open(filename)
seq = []
try:
while 1:
seq.append(im.resize((480, 270)).copy())
im.seek(len(seq)) # skip to next frame
except EOFError:
pass
try:
self.delay = im.info['duration']
except KeyError:
self.delay = 45
first = seq[0].convert('RGB')
self.frames = [ImageTk.PhotoImage(first)]
tkinter.Label.__init__(self, master, image=self.frames[0])
temp = seq[0].convert('RGB')
for image in seq[1:]:
frame = image.convert('RGB')
temp.paste(frame)
self.frames.append(ImageTk.PhotoImage(temp))
self.idx = 0
self.cancel = self.after(self.delay, self.play)
def play(self):
self.config(image=self.frames[self.idx])
self.idx += 1
if self.idx == len(self.frames):
self.idx = 0
self.cancel = self.after(self.delay, self.play)
lbl = MyLabel(window, '*****.gif')
lbl.pack(anchor="center")
window.mainloop()
I have taken a look at the solution provided at the link Displaying animated GIFs in Tkinter using PIL however I could not get them to work. Please assist.