import tkinter as tk
from itertools import count
from PIL import Image, ImageTk


class AnimatedGIF(tk.Label):
    def __init__(self, root, gif_file, *args, **kwargs):
        tk.Label.__init__(self, root, *args, **kwargs)
        self.root = root
        self.gif_file = gif_file
        self.frames = []
        self.load_gif()

    def load_gif(self):
        """Load the GIF frames."""
        try:
            with Image.open(self.gif_file) as img:
                for frame in count(1):
                    self.frames.append(ImageTk.PhotoImage(img.copy()))
                    img.seek(frame)
        except EOFError:
            pass
        self.show_animation()

    def show_animation(self):
        """Display the animation."""

        def update_frame(frame_index):
            self.configure(image=self.frames[frame_index])
            self.root.after(100, update_frame, (frame_index + 1) % len(self.frames))

        update_frame(0)


if __name__ == "__main__":
    root = tk.Tk()
    gif_label = AnimatedGIF(root, r"C:\Users\Administrator.DESKTOP-0DNOS3E\AppData\Roaming\.NFLmusic\resource\images\loading.gif")
    gif_label.pack()
    root.mainloop()
