29 lines
809 B
Python
29 lines
809 B
Python
from itertools import count
|
|
from PIL import Image, ImageTk
|
|
|
|
|
|
def load_gif(gif_file):
|
|
"""Load GIF frames from the specified file."""
|
|
frames = []
|
|
try:
|
|
with Image.open(gif_file) as img:
|
|
for frame in count(1):
|
|
frames.append(ImageTk.PhotoImage(img.copy()))
|
|
img.seek(frame)
|
|
except EOFError:
|
|
pass
|
|
return frames
|
|
|
|
|
|
def show_animation(label, frames):
|
|
"""Display the animation on the specified label."""
|
|
def update_frame(frame_index):
|
|
if not getattr(label, 'stop_animation', False):
|
|
label.configure(image=frames[frame_index])
|
|
label.after(100, update_frame, (frame_index + 1) % len(frames))
|
|
update_frame(0)
|
|
|
|
|
|
def stop_animation(label):
|
|
"""Stop the animation."""
|
|
label.stop_animation = True |