NFLmusic库文件
This commit is contained in:
29
nflmusic/load_gif.py
Normal file
29
nflmusic/load_gif.py
Normal file
@ -0,0 +1,29 @@
|
||||
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
|
Reference in New Issue
Block a user