You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
659 B
23 lines
659 B
import tkinter as tk |
|
import itertools |
|
|
|
class AnimatedGif: |
|
def __init__(self, path): |
|
self.frames = [] |
|
self.load_frames(path) |
|
self.index = itertools.cycle(range(len(self.frames))) |
|
|
|
def load_frames(self, path): |
|
i = 0 |
|
while True: |
|
try: |
|
image = tk.PhotoImage(file=path, format='gif -index %i' %(i)) |
|
resized_image = image.subsample(1) # Resize image to half |
|
self.frames.append(resized_image) |
|
|
|
i += 1 |
|
except tk.TclError: |
|
break |
|
|
|
def next_frame(self): |
|
return self.frames[next(self.index)] |