Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
I added a note regarding efficiency.
Source Link
Apostolos
  • 3.5k
  • 29
  • 37

It's really incredible ... All are proposing some special package for playing an animated GIF, at the moment that it can be done with Tkinter and the classic PIL module!

Here is my own GIF animation method (I created a while ago). Very simple:

from Tkinter import * from PIL import Image, ImageTk from time import sleep def stop(event): global play play = False exit() root = Tk() root.bind("<Key>", stop) # Press any key to stop GIFfile = {path_to_your_GIF_file} im = Image.open(GIFfile); img = ImageTk.PhotoImage(im) delay = float(im.info['duration'])/1000; # Delay used in the GIF file lbl = Label(image=img); lbl.pack() # Create a label where to display images play = True; frame = 0 while play: sleep(delay); frame += 1 try: im.seek(frame); img = ImageTk.PhotoImage(im) lbl.config(image=img); root.update() # Show the new frame/image except EOFError: frame = 0 # Restart root.mainloop() 

You can set your own means to stop the animation. Let me know if you like to get the full version with play/pause/quit buttons.

Note: I am not sure if the consecutive frames are read from memory or from the file (disk). In the second case it would be more efficient if they all read at once and saved into an array (list). (I'm not so interested to find out! :)

It's really incredible ... All are proposing some special package for playing an animated GIF, at the moment that it can be done with Tkinter and the classic PIL module!

Here is my own GIF animation method. Very simple:

from Tkinter import * from PIL import Image, ImageTk from time import sleep def stop(event): global play play = False exit() root = Tk() root.bind("<Key>", stop) # Press any key to stop GIFfile = {path_to_your_GIF_file} im = Image.open(GIFfile); img = ImageTk.PhotoImage(im) delay = float(im.info['duration'])/1000; # Delay used in the GIF file lbl = Label(image=img); lbl.pack() # Create a label where to display images play = True; frame = 0 while play: sleep(delay); frame += 1 try: im.seek(frame); img = ImageTk.PhotoImage(im) lbl.config(image=img); root.update() # Show the new frame/image except EOFError: frame = 0 # Restart root.mainloop() 

You can set your own means to stop the animation. Let me know if you like to get the full version with play/pause/quit buttons.

It's really incredible ... All are proposing some special package for playing an animated GIF, at the moment that it can be done with Tkinter and the classic PIL module!

Here is my own GIF animation method (I created a while ago). Very simple:

from Tkinter import * from PIL import Image, ImageTk from time import sleep def stop(event): global play play = False exit() root = Tk() root.bind("<Key>", stop) # Press any key to stop GIFfile = {path_to_your_GIF_file} im = Image.open(GIFfile); img = ImageTk.PhotoImage(im) delay = float(im.info['duration'])/1000; # Delay used in the GIF file lbl = Label(image=img); lbl.pack() # Create a label where to display images play = True; frame = 0 while play: sleep(delay); frame += 1 try: im.seek(frame); img = ImageTk.PhotoImage(im) lbl.config(image=img); root.update() # Show the new frame/image except EOFError: frame = 0 # Restart root.mainloop() 

You can set your own means to stop the animation. Let me know if you like to get the full version with play/pause/quit buttons.

Note: I am not sure if the consecutive frames are read from memory or from the file (disk). In the second case it would be more efficient if they all read at once and saved into an array (list). (I'm not so interested to find out! :)

I offered a simple solution
Source Link
Apostolos
  • 3.5k
  • 29
  • 37

It's really incredible ... All are proposing some special package for playing an animated GIF, at the moment that it can be done with Tkinter and the classic PIL module! See No transparency in animated gif with Tkinter

Here is my own GIF animation method. This was enough forVery simple:

from Tkinter import * from PIL import Image, ImageTk from time import sleep def stop(event): global play play = False exit() root = Tk() root.bind("<Key>", stop) # Press any key to stop GIFfile = {path_to_your_GIF_file} im = Image.open(GIFfile); img = ImageTk.PhotoImage(im) delay = float(im.info['duration'])/1000; # Delay used in the GIF file lbl = Label(image=img); lbl.pack() # Create a label where to display images play = True; frame = 0 while play: sleep(delay); frame += 1 try: im.seek(frame); img = ImageTk.PhotoImage(im) lbl.config(image=img); root.update() # Show the new frame/image except EOFError: frame = 0 # Restart root.mainloop() 

You can set your own means to stop the animation. Let me, but I am sure there must be more know if you like to get the full version with just these requirementsplay/pause/quit buttons.

It's really incredible ... All are proposing some special package for playing an animated GIF, at the moment that it can be done with Tkinter and the classic PIL module! See No transparency in animated gif with Tkinter. This was enough for me, but I am sure there must be more with just these requirements.

It's really incredible ... All are proposing some special package for playing an animated GIF, at the moment that it can be done with Tkinter and the classic PIL module!

Here is my own GIF animation method. Very simple:

from Tkinter import * from PIL import Image, ImageTk from time import sleep def stop(event): global play play = False exit() root = Tk() root.bind("<Key>", stop) # Press any key to stop GIFfile = {path_to_your_GIF_file} im = Image.open(GIFfile); img = ImageTk.PhotoImage(im) delay = float(im.info['duration'])/1000; # Delay used in the GIF file lbl = Label(image=img); lbl.pack() # Create a label where to display images play = True; frame = 0 while play: sleep(delay); frame += 1 try: im.seek(frame); img = ImageTk.PhotoImage(im) lbl.config(image=img); root.update() # Show the new frame/image except EOFError: frame = 0 # Restart root.mainloop() 

You can set your own means to stop the animation. Let me know if you like to get the full version with play/pause/quit buttons.

Source Link
Apostolos
  • 3.5k
  • 29
  • 37

It's really incredible ... All are proposing some special package for playing an animated GIF, at the moment that it can be done with Tkinter and the classic PIL module! See No transparency in animated gif with Tkinter. This was enough for me, but I am sure there must be more with just these requirements.