title: Exception in Tkinter callback When you press button 1 again
body: <p>I have a problem asking for your help, I'm doing opencv based face detection, it's done step by step.
  1. Get information of person based on id
  2. take the person's face
  3. Training
  After I got the information of the first person, I did step 2 to get that person's face
  Next is to get the information of the second person, but it failed in the part where the 2nd person's face was.
  How can I fix it, please help me</p>
  <pre><code>        enter code here` db = mysql.connector.connect(**config)
          db.set_converter_class(NumpyMySQLConverter)
          
          # connect to mysql
          def get_db():
              global db
              if db.is_connected():
                  pass
              else:
                  db = mysql.connector.connect(**config)
          def insertOrUpdate():
              # ket noi db
              # kiem tra id nhap vao ton tai hay chua ?
              get_db()
              cid = ent.get()
              cname = ent2.get()
              birthday = ent7.get_date()
              ccountry = ent4.get()
              carea = ent5.get()
              cphone = ent6.get()
              if (cid == &quot;&quot; or cname == &quot;&quot; or birthday==&quot;&quot; or ccountry==&quot;&quot; or carea==&quot;&quot;):
                  messagebox.showinfo(&quot;Error&quot;, &quot;field is not empty&quot;)
              # cphone = re.compile(r'^(?:\+?44)?[07]\d{9,13}$')
              # if not cphone.search():
              #     messagebox.showinfo(&quot;Error&quot;, &quot;field is not empty&quot;)
              mycursor = db.cursor()
              sql = (&quot;select * from db_people WHERE id=&quot;+ str(cid))
              mycursor.execute(sql,cid)
              myresult = mycursor.fetchall()
              print(myresult)
              isRecordExist = 0
              # duyet hang tren bang ghi
              for row in myresult:
                  print(&quot;chay khong&quot;)
                  isRecordExist =1
              print(isRecordExist)
              if(isRecordExist == 0):
                  # cid = ent.get()
                  # cname=ent2.get()
                  # birthday = ent7.get_date()
                  # ccountry = ent4.get()
                  # carea =ent5.get()
                  # cphone= ent6.get()
                  # print(cid)
                  if(radio.get() ==&quot;Male&quot;):
                      sql = &quot;INSERT INTO db_people(id,user_name,gender,dateOfBirth,country,area,phone) 
                             VALUES(%s,%s,%s,%s,%s,%s,%s)&quot;
                      val = (cid, cname, str(radio.get()), birthday,ccountry, carea, cphone)
                  else:
                      sql = &quot;INSERT INTO db_people(id,user_name,gender,dateOfBirth,country,area,phone) 
                             VALUES(%s,%s,%s,%s,%s,%s,%s)&quot;
                      val = (cid, cname, str(radio.get()), birthday,ccountry, carea, cphone)
              else:
                  query = &quot;UPDATE db_people SET user_name='&quot; + str(user_name)+&quot;' WHERE id=&quot; + str(cid)
          
              print(&quot;done&quot;)
              # thuc thi lenh
              mycursor.execute(sql,val)
              db.commit()
              messagebox.showinfo(&quot;Message&quot;, &quot;Success&quot;)
              db.close()
          
             # load thu vien opencv
             face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades+ 
             &quot;haarcascade_frontalface_default.xml&quot;)
             cap = cv2.VideoCapture(0)
          
          # UI
          win = Tk()
          
          frame = tk.Frame(master=win, width=400, height=800)
          frame.pack()
          label0 = tk.Label(master=frame, text=&quot;Employee Infomation &quot;)
          label0.place(x=100, y=20)
          
          
          id = StringVar()
          c_id = StringVar()
          label1 = Label(frame,textvariable=id)
          id.set(&quot;Enter id&quot;)
          label1.place(x =0 ,y =60)
          ent = Entry(frame,textvariable=c_id,width=40)
          ent.place(x =70 , y=60)
          
          
          user_name = StringVar()
          c_name = StringVar()
          label2 = Label(frame,textvariable=user_name)
          user_name.set(&quot;Enter name&quot;)
          label2.place(x =0 ,y =100)
          ent2 = Entry(frame,textvariable=c_name,width=40)
          ent2.place(x =70 , y=100)
          
          
          gender = StringVar()
          radio = tk.StringVar()
          label3 = Label(frame,textvariable=gender)
          gender.set(&quot;Gender&quot;)
          label3.place(x =0 ,y =140)
          r1 = Radiobutton(win,text=&quot;Male&quot;,variable= radio,value=&quot;Male&quot;)
          r1.pack()
          r1.place(x =120 , y=140)
          r2 = Radiobutton(win,text=&quot;Female&quot;,variable= radio,value=&quot;Female&quot;)
          r2.pack()
          r2.place(x =180 , y=140)
          
          dayOfbirh = StringVar()
          c_birth = 'm/d/y'
          label7 = Label(frame,textvariable=dayOfbirh)
          dayOfbirh.set(&quot;DayOfBirth&quot;)
          label7.place(x =0 ,y =180)
          
          ent7 = DateEntry(frame,date_pattern=c_birth,background=&quot;blue&quot;,foreground=&quot;white&quot;,borderwidth = 
                 2,width=37)
          ent7.place(x =70 ,y =180)
          
          
          area = StringVar()
          c_area = StringVar()
          label5 = Label(frame,textvariable=area)
          area.set(&quot;Work place&quot;)
          label5.place(x =0 ,y =220)
          ent5 = Entry(frame,textvariable=c_area,width=40)
          ent5.place(x =70 ,y =220)
          
          country = StringVar()
          c_country = StringVar()
          label4 = Label(frame,textvariable=country)
          country.set(&quot;Address&quot;)
          label4.place(x =0 ,y =300)
          ent4 = Entry(frame,textvariable=c_country,width=40)
          ent4.place(x =70 ,y =300)
          
          phone = StringVar()
          c_phone = StringVar()
          label6 = Label(frame,textvariable=phone)
          phone.set(&quot;Phone&quot;)
          label6.place(x =0 ,y =260)
          ent6 = Entry(frame,textvariable=c_phone,width=40)
          ent6.place(x =70 ,y =260)
          
          def Trainning():
              import trainData
          def logout():
              import detect_mask_video
              # win.destroy()
              # import login
          # lay db tu camera
          def opencam():
              sampleNum = 0
              while(True):
                  ret, frame = cap.read()
                  # chuyen anh thanh mau xam de training
                  gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
          
                  faces = face_cascade.detectMultiScale(gray,1.3, 5)
          
                  for (x, y, w, h) in faces:
                      cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
                      # tao folder dataset va kiem tra
                      if os.path.exists('dataset/image_trainning'):
                          sampleNum += 1
                      id = c_id.get()
                      cv2.imwrite('dataset/image_trainning/User.' + str(id) + '.' + str(sampleNum) + 
                       '.jpg', gray[y: y + h, x: x + w])
          
                  cv2.imshow('frame', frame)
                  cv2.waitKey(1)
          
                  if sampleNum &gt; 10:
                      break;
              cap.release()
              cv2.destroyAllWindows()
          btn1 = Button(frame,text=&quot;1.Get Infor&quot;, command=insertOrUpdate).place(x =5 ,y =350)
          btn3 = Button(frame,text=&quot;3.Trainning&quot;, command=Trainning).place(x =170 ,y =350)
          btn4 = Button(frame,text=&quot;4.Camera&quot;, command=logout).place(x =260 ,y =350)
          btn2 = Button(frame,text=&quot;2.Get Image&quot;, command=opencam).place(x =80 ,y =350)
          win.title(&quot;Information employee&quot;)
          win.geometry(&quot;490x400&quot;)
          win.resizable(False,False)
          win.mainloop()
  
  
  this is error: 
  Exception in Tkinter callback
  Traceback (most recent call last):
    File &quot;C:\Users\PC\anaconda3\lib\tkinter\__init__.py&quot;, line 1883, in __call__
      return self.func(*args)
    File &quot;C:/Users/PC/Desktop/bk/Capstone2_backup/getData.py&quot;, line 183, in opencam
      gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-j8nxabm_\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
  </code></pre>