Play Animationen in GIF mit Tkinter [duplizieren]
Diese Frage hat hier bereits eine Antwort:
Spielen Sie ein animiertes GIF in Python mit tkinter 1 Antwort Ich habe versucht, ein animiertes GIF mit @ abzuspieleTkinter.PhotoImage
, habe aber keinen Erfolg gesehen. Es zeigt das Bild, aber nicht die Animation. Das Folgende ist mein Code:
root = Tkinter.Tk()
photo = Tkinter.PhotoImage(file = "path/to/image.gif")
label = Tkinter.Label(image = photo)
label.pack()
root.mainloop()
It zeigt das Bild in einem Fenster an und das war's. Ich denke, dass das Problem etwas mit @ zu tun hTkinter.Label
aber ich bin mir nicht sicher. Ich habe nach Lösungen gesucht, aber alle fordern mich auf, PIL (Python Imaging Library) zu verwenden, und das ist etwas, das ich nicht verwenden möchte.
Mit der Antwort habe ich noch etwas Code erstellt (der immer noch nicht funktioniert ...), hier ist er:
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()
Danke für alles! :)