title: Motion Detector GUI
body: <p>I have been trying to make a GUI of the Motion detector app thought in Section 29 using tkinter, I want it to be like, there will be 4 diffrent buttons, 4 functioning for the diffrent frame which is Delta frame, Grayscale, colored and Threshold frame.
  I have been trying this, but when i do it.</p>
  <p>The button functions but the frame it shows is always the first frame, it doesnt update.</p>
  <p>My code:</p>
  <pre><code>import tkinter
  import cv2, time
  from tkinter import *
  from tkinter import ttk
   
  top = tkinter.Tk()
   
  first_frame=None
  video=cv2.VideoCapture(0)
   
   
  while True:
      check, frame = video.read()
   
      gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
      gray=cv2.GaussianBlur(gray,(21,21),0)
   
      if first_frame is None:
          first_frame=gray
          continue
   
      delta_frame=cv2.absdiff(first_frame,gray)
   
      thresh_delta=cv2.threshold(delta_frame, 30, 255, cv2.THRESH_BINARY)[1]
   
      thresh_delta=cv2.dilate(thresh_delta, None, iterations=2)
   
      (cnts,_) = cv2.findContours(thresh_delta.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
   
      for countour in cnts:
          if cv2.contourArea(countour) &lt; 1000:
              continue
      
          (x, y, w, h) = cv2.boundingRect(countour)
          cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 3)    
   
      def Gray():
          cv2.imshow(&quot;Gray&quot;,gray)
      cv2.imshow(&quot;delta frame&quot;, delta_frame)
      cv2.imshow(&quot;Threshold Delta Frame&quot;, thresh_delta)
      cv2.imshow(&quot;Color Frame&quot;, frame)
   
      Button_Gray= tkinter.Button(top, text=&quot;Grayscale&quot;, command= Gray)
      Button_Gray.pack()
      top.mainloop()
     
      key=cv2.waitKey(1)
      print(gray)
   
      if key==ord(&quot;q&quot;):
          break
   
   
  video.realease()
  cv2.destroyAllWindows
  </code></pre>
  <p>Would appreciate quick help!</p>
  <p>Regards
  Gaurav SINGH</p>