Python Tkinter AttributeError

nBeryXD

Centipat
Katılım
20 Ağustos 2021
Mesajlar
23
Daha fazla  
Cinsiyet
Erkek
def fonksiyonu içinde "destroy" kullandığımda hata veriyor.

Python:
import cv2
cap = cv2.VideoCapture(0) # video capture source camera (Here webcam of laptop)
ret,frame = cap.read() # return a single frame in variable `frame`
from tkinter import *
from time import sleep
sp = 0
def shot():
    global sp
    sp = sp + 1
    cv2.imwrite('images/c%s.png' % sp ,frame)
    lbl2_3 = Label(window, text="3" ).place(x = 20, y =  10)
    lbl2_3.after(1000, lbl2_3.destroy)
    lbl2_2 = Label(window, text="2" ).place(x = 20, y = 10 )
    lbl2_2.after(1000, lbl2_2.destroy)
    lbl2_1 = Label(window, text="1" ).place(x = 20, y = 10 )
    lbl2_1.after(1000, lbl2_1.destroy)
    lbl2_T = Label(window, text="TAKED" ).place(x = 20, y = 10 )
    lbl2_T.after(1000, lbl2_T.destroy)
    cv2.imwrite('images/c%s.png' % sp ,frame)


window = Tk()
window.title("taking photo, be stayfished")
window.geometry('350x200')
lbl = Label(window, text="photo")
lbl.grid(column=0, row=0)
btn = Button(window, text="shot!", command = shot)
btn.grid(column=1, row=0)
window.mainloop()

error

Python:
line 19, in shot
    lbl2_3.after(1000, lbl2_3.destroy)
AttributeError: 'NoneType' object has no attribute 'after'
 

Technopat Haberler

Geri
Yukarı