problem with insert GIF in python(TKinter)?

How to make it so that the gif was not in the main window (menu, greeting), but in the final window . I was able to insert a gif in the beginning of the program, but in the final window did not work, how to make the final with a gif, if I have this code :

import tkinter as tk
from PIL import Image, ImageTk

def open_second_window():
    second_window = tk.Toplevel(root)
    second_window.title("SECOND")
    second_window.state('zoomed')
 
    image_path = "1.jpg"
    image = Image.open(image_path)
    photo = ImageTk.PhotoImage(image)


    label = tk.Label(second_window, image=photo)
    label.image = photo 
    label.pack(fill=tk.BOTH, expand=True)
    label.place(x=770, y=0)
 
    button = tk.Button(second_window,height=4, width=12, font='Times 31', text="ONE", command=lambda: open_four_window(second_window))

    button.place(x=308, y=82, anchor='ne')
    button1 = tk.Button(second_window,height=4, width=12, font='Times 31', wraplength=289, text="TWO", command=open_five_window)
    button1.place(x=688, y=82, anchor='ne')
    button = tk.Button(second_window,height=4, width=12, font='Times 31', text="THREE", command=open_threee_window)
    button.place(x=308, y=352, anchor='ne')
    button1 = tk.Button(second_window,height=4, width=12, font='Times 31', text="FOUR", command=open_threetenfive_window)
    button1.place(x=688, y=352, anchor='ne')


    tk.Label(second_window, font='Times 30', text="TEXT", fg="red").place(x=150, y=30)


    third_window.grab_set()
def open_four_window(second_window):

    second_window.destroy()

    four_window = tk.Toplevel(root)
    four_window.title("THREE")
    four_window.state('zoomed')

    image_path = "2.jpg"
    image = Image.open(image_path)
    photo = ImageTk.PhotoImage(image)

    label = tk.Label(four_window, image=photo)
    label.image = photo  
    label.pack(fill=tk.BOTH, expand=True)
    label.place(x=0, y=0)


    button = tk.Button(four_window,height=1, width=33, font='Times 31', text="START", command=lambda: open_second_window())
    button.place(x=768, y=720, anchor='ne')
    button1 = tk.Button(four_window,height=1, width=33, font='Times 31', text="EXIT", command=animation)
    button1.place(x=1536, y=720, anchor='ne')



    third_window.grab_set()


...

def open_theend_window():
    # Создаем дочернее окно
    theend_window = tk.Toplevel(root)
    theend_window.title("Второе окно")
    theend_window.state('zoomed')

    photo = tkinter.PhotoImage(file = 'road-sign-roadtrip.gif')
    lbl = tkinter.Label(theend_window ,image = photo)
    lbl.image = photo #keeping a reference in this line
    lbl.grid(row=0, column=0)

    # Создаем метку для отображения изображения
    
     # Сохраняем ссылку на изображение



    # Создаем кнопку 
    button = tk.Button(theend_window,height=1, width=33, font='Times 31', text="В начало", command=lambda: open_second_window())
    button.place(x=768, y=720, anchor='ne')
    button1 = tk.Button(theend_window,height=1, width=33, font='Times 31', text="Выход", command=Close)
    button1.place(x=1536, y=720, anchor='ne')



    # Устанавливаем режим grab_set()
    third_window.grab_set()






5# Создаем главное окно
root = tk.Tk()
root.title("Главное окно")
root.state('zoomed')


# Загружаем изображение 001.jpg
image_path = "40.jpg"
image = Image.open(image_path)
photo = ImageTk.PhotoImage(image)
image.thumbnail((1, 1))

# Создаем метку для отображения изображения
label = tk.Label(root, image=photo)
label.pack(fill=tk.BOTH, expand=True)
label.place(x=-3, y=0)

def Close(): 
    root.destroy() 

# Создаем кнопку "Далее"
button = tk.Button(root,height=1, width=33, font='Times 31', text="NEXT", command=lambda: open_second_window())
button.place(x=768, y=720, anchor='ne')
button1 = tk.Button(root,height=1, width=33, font='Times 31', text="EXIT", command=Close)
button1.place(x=1536, y=720, anchor='ne')


tk.Label(root, font='Times 30', text="TEXT", fg="red").pack(padx=30, pady=30)
tk.Label(root, font='Times 30 italic', text="DESCRIPTION").place(x=600, y=77)

file = "road-sign-roadtrip.gif"
info = Image.open(file)

frames = info.n_frames  # number of frames

photoimage_objects = []
for i in range(frames):
    obj = tk.PhotoImage(file=file, format=f"gif -index {i}")
    photoimage_objects.append(obj)


def animation(current_frame=0):
    global loop
    image = photoimage_objects[current_frame]

    gif_label.configure(image=image)
    current_frame = current_frame + 1

    if current_frame == frames:
        current_frame = 0

    loop = root.after(50, lambda: animation(current_frame))

gif_label = tk.Label(root, image="")
gif_label.pack()

root.mainloop()

I made only the ability to play a GIF, but only in the main window, and I need to be in the final window. In my program is quite a lot of functions (windows) and I did not write them, as it works.

5

I think the logic is fine; there are just some typos that need fixing and some variables that need declaring.

Here are some examples of changes that made the gif animate for me:

def open_second_window():
    # omitting declarations…
    button1 = tk.Button(
        second_window, # omitting props…
        command=open_third_window) # Changed from undefined "open_five_window"
    button = tk.Button(
        second_window,
        command=open_third_window)# Typo: was "open_threee_window"


# Renaming def open_theend_window():
def open_third_window():
    # Updated from tkinter. to tk. since that's how you imported it
    third_window = tk.Toplevel(root)
    photo = tk.PhotoImage(file='road-sign-roadtrip.gif')
    button = tk.Button(
        third_window,
        command=open_second_window)

Judging from the usage I think you’re developing a proof of concept for a tkinter app with images. If that’s the case, I hope I helped you get closer! If this is intended for users, then it might be too challenging to understand.
I would recommend considering user stories for developing the use cases.

Regardless, I recommend developing with an editor that has syntax highlighting, like PyCharm or VSCode with python and autopep8 plugins. These tools can highlight typos and mistakes and save you a lot of time in the future.

Happy coding!

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật