python - Play Animations in GIF with Tkinter -
i've been trying play animated gif using tkinter.photoimage
, haven't been seeing success. displays image, not animation. following code:
root = tkinter.tk() photo = tkinter.photoimage(file = "path/to/image.gif") label = tkinter.label(image = photo) label.pack() root.mainloop()
it displays image in window, , that's it. i'm thinking issue has tkinter.label
i'm not sure. i've looked solutions tell me use pil (python imaging library), , it's don't want use.
with answer, created more code (which still doesn't work...), here is:
from tkinter import * def run_animation(): while true: try: global photo global frame global label photo = photoimage( file = photo_path, format = "gif - {}".format(frame) ) label.configure(image = nextframe) frame = frame + 1 except exception: frame = 1 break root = tk() photo_path = "/users/zinedine/downloads/091.gif" photo = photoimage( file = photo_path, ) label = label( image = photo ) animate = button( root, text = "animate", command = run_animation ) label.pack() animate.pack() root.mainloop()
thanks everything! :)
you have drive animation in tk. animated gif consists of number of frames in single file. tk loads first frame can specify different frames passing index parameter when creating image. example:
frame2 = photoimage(file=imagefilename, format="gif -index 2")
if load frames separate photoimages , use timer events switch frame being shown (label.configure(image=nextframe)
). delay on timer lets control animation speed. there nothing provided give number of frames in image other failing create frame once exceed frame count.
see photo tk manual page official word.
Comments
Post a Comment