Search code examples
pythontkinterpython-imaging-librarygifanimated-gif

Animated GIF with Python Tkinter? No more PIL module?


I am new to developing and programming, and recently I've been trying to create a GUI program with Python Tkinter. In this program I wanted the background to be a looping gif with 90 frames.

Having already looked up everywhere I could, here on Stack Overflow and other videos on YouTube about the topic to understand how to make this, it seems I can't do it due to some "techinical issues".

Correct me if I'm wrong, but has the PIL library gone in the latest version of Python? Or changed it's usage? Is it really necessary? Would a nice way to do this is by changing the active frame using a index variable to loop through frames 0-89?

Whenever I try to import it, with various ways, I just get "ModuleNotFoundError: No module named 'PIL' "

Any suggestion on what's the best method to animate a background gif?

Notes: I'm using JetBrains PyCharm Comunnity Edition 2017

Here's my code without any attempt of animating

from tkinter import *
import tkinter.messagebox

root = Tk()
root.title("GinelHUB")
root.resizable(width=False, height=False)
root.geometry("390x300+750+300")
root.configure(background='#1a1a1a')

fundoFoda = PhotoImage(file="cascade.gif", format="gif")

bg = Label(image=fundoFoda)
bg.place(x=0, y=0, relwidth=1, relheight=1)

root.mainloop()

Solution

  • Development on the official PIL has been stopped, however, a fork called Pillow is available for you to use. That being said, it's still a bad option to use this for animated gifs. For that, look into ImageMagik. You'll find it more convinient to work with.