code to run gif tkinter

Solutions on MaxInterview for code to run gif tkinter by the best coders in the world

showing results for - "code to run gif tkinter"
Wiley
15 Jan 2019
1#code by TigerhawkT3 (on YT and github)
2import tkinter
3from PIL import Image, ImageTk, ImageSequence
4
5class App:
6    def __init__(self, parent):
7        self.parent = parent
8        self.canvas = tkinter.Canvas(parent, width=400, height=400)
9        self.canvas.pack()
10        self.sequence = [ImageTk.PhotoImage(img)
11                            for img in ImageSequence.Iterator(
12                                    Image.open(
13                                    r'gif2.gif'))]
14        self.image = self.canvas.create_image(200,200, image=self.sequence[0])
15        self.animate(1)
16    def animate(self, counter):
17        self.canvas.itemconfig(self.image, image=self.sequence[counter])
18        self.parent.after(20, lambda: self.animate((counter+1) % len(self.sequence)))
19
20root = tkinter.Tk()
21app = App(root)
22root.mainloop()