Gif with Tkinter

Asked

Viewed 47 times

0

I have a problem here.. I’m trying to make two gifs stand on top of each other when called, simulating a sensor. When it doesn’t detect anything, it shows a gif, when detected, it shows another gif on top of that first gif. Then when it is no longer detecting anything, it deletes this second gif and shows only 1.

import tkinter as tk
from PIL import Image

root = tk.Tk()
root.geometry("600x400")

file1 = "Python\Programas\Sensor de Presença\!Detectado.gif"
file2 = "Python\Programas\Sensor de Presença\Detectado.gif"

info_1 = Image.open(file1)
info_2 = Image.open(file2)

frames_1 = info_1.n_frames
frames_2 = info_2.n_frames

im_g1 = [tk.PhotoImage(file=file1, format=f"gif -index {i}") for i in range(frames_1)]
im_g2 = [tk.PhotoImage(file=file2, format=f"gif -index {i}") for i in range(frames_2)]

count_1 = 0
count_2 = 0

anim_1 = None
anim_2 = None


def GIFverde(count_1):
    global anim_1

    gif1 = im_g1[count_1]

    gif_label_1.configure(image=gif1)
    count_1 += 1
    if count_1 == frames_1:
       count_1 = 0
    anim_1 = root.after(80, lambda: GIFverde(count_1))

def GIFvermelho(count_2):

   global anim_2

   gif2 = im_g2[count_2]

   gif_label_2.configure(image=gif2)
   count_2 += 1
   if count_2 == frames_2:
       count_2 = 0
   anim_2 = root.after(60, lambda: GIFvermelho(count_2))


gif_label_1 = tk.Label(root)
gif_label_1.place(x=0,y=0)
gif_label_2 = tk.Label(root)
gif_label_2.place(x=0,y=0)


bt1 = tk.Button(root, text="Detectou movimento",command=lambda: GIFvermelho(count_2))
bt1.pack(side="bottom")

bt2 = tk.Button(root, text="Não detectou movimento",command=lambda: GIFverde(count_1))
bt2.pack(side="bottom")

root.mainloop()
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.