Ich habe versucht, ein animiertes GIF unter Verwendung Tkinter.PhotoImage
zu spielen, aber habe keinen Erfolg gesehen. Es zeigt das Bild, aber nicht die Animation an. Das Folgende ist mein Code:Animationen in GIF mit Tkinter abspielen
root = Tkinter.Tk()
photo = Tkinter.PhotoImage(file = "path/to/image.gif")
label = Tkinter.Label(image = photo)
label.pack()
root.mainloop()
Es zeigt das Bild in einem Fenster, und das ist es. Ich denke, dass das Problem etwas mit Tkinter.Label
zu tun hat, aber ich bin mir nicht sicher. Ich habe nach Lösungen gesucht, aber alle sagen mir, dass ich PIL (Python Imaging Library) verwenden soll, und das möchte ich nicht verwenden.
Mit der Antwort, habe ich etwas mehr Code (das funktioniert immer noch nicht ...), hier ist es:
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 = "https://stackoverflow.com/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()
Vielen Dank für alles! :)
Sie könnten überprüfen, ob es durch die Verwendung es stattdessen auf einem 'Canvas' Widget (' C zu einem 'Label' Widget angebracht hat etwas mit dem Sein create_image (x, y, image = photo'). – martineau
Ich weiß nicht, ob ich etwas mit 'Canvas' falsch mache, aber ich bekomme nur die untere rechte Ecke meines Bildes und es sieht pixelig aus ... – Zizouz212
Versuch es zu bekommen es funktioniert zuerst mit einem nicht-animierten Bild, dann wechseln Sie zu einem animierten. – martineau