title: display video camera on two different windows tkinter python
body: <p>i have a GUI python application that contain two different function windows and i'am trying to display video camera in the second window of tkinter application.
  But, the video frame always be showing on the first windows!! i don't know if it is a problem of threads, or camera librairy. is there any fault in my code?
  thanks in advance.</p>
  <pre><code># add the necessairy librairy
      import tkinter as tk
      import threading
      import time
      import subprocess
      from imutils.video import VideoStream
      import time
      import imutils
      import cv2
      import argparse
      from PIL import Image
      from PIL import ImageTk
      
      class PhotoBoothApp:
          def __init__(self,vs):
              # store the video stream object and output path, then initialize
              # the most recently read frame, thread for reading frames, and
              # the thread stop event
      
              self.vs = vs
              self.frame = None
              self.thread = None
              self.stopEvent_2 = None
      
              # initialize the root window and image panel
              self.root = tk.Tk()
              self.panel = None
              self.user_input = tk.StringVar(self.root)
              self.but_frame = tk.Frame(self.root)
              w = 800 # width for the Tk root
              h = 500 # height for the Tk root
              # get screen width and height
              ws = self.root.winfo_screenwidth() # width of the screen
              hs = self.root.winfo_screenheight() # height of the screen
              # calculate x and y coordinates for the Tk master window
              x = (ws/3) - (w/3)
              y = (hs/3) - (h/3)
              # set the dimensions of the screen 
              # and where it is placed
              self.root.geometry('%dx%d+%d+%d' % (w, h, x, y))
              # when open the second window i want it to be on toplevel; it means when i click outside the frame it won't get hide
              self.root.title(&quot;Test thread&quot;)
      
              # create a button, that when pressed, will take the current
              # frame and save it to file
              btn = tk.Button(self.but_frame, bd = '5',text=&quot; photo &quot;)
              
              self.but_frame.pack(side=&quot;left&quot;)
                      
              # start a thread that constantly pools the video sensor for
              # the most recently read frame
              self.stopEvent_2 = threading.Event()
              self.thread = threading.Thread(target=self.videoLoop, args=())
              self.thread.start()
      
              # set a callback to handle when the window is closed
              self.root.wm_protocol(&quot;WM_DELETE_WINDOW&quot;, self.onClose)
  
          def videoLoop(self):
              # DISCLAIMER:
              # I'm not a GUI developer, nor do I even pretend to be. This
              # try/except statement is a pretty ugly hack to get around
              # a RunTime error that Tkinter throws due to threading
      
              try:
                  # keep looping over frames until we are instructed to stop
                  while not self.stopEvent_2.is_set():
                      # grab the frame from the video stream and resize it to
                      # have a maximum width of 300 pixels
                      self.frame = self.vs.read()
                      self.frame = imutils.resize(self.frame, width=300)
      
                      #cv2.imshow('video player', self.frame) 
              
                      # OpenCV represents images in BGR order; however PIL
                      # represents images in RGB order, so we need to swap
                      # the channels, then convert to PIL and ImageTk format
                      image = cv2.cvtColor(self.frame, cv2.COLOR_BGR2RGB)
                      image = Image.fromarray(image)
                      image = ImageTk.PhotoImage(image)
              
                      # if the panel is not None, we need to initialize it
                      if self.panel is None:
                          self.panel = tk.Label(image=image)
                          self.panel.image = image
                          self.panel.pack(side=&quot;left&quot;, padx=10, pady=10)
              
                      # otherwise, simply update the panel
                      else:
                          self.panel.configure(image=image)
                          self.panel.image = image
      
              except RuntimeError :
                  print(&quot;[INFO] caught a RuntimeError_________________________________________&quot;)
      
          def onClose(self):
              # set the stop event, cleanup the camera, and allow the rest of
              # the quit process to continue
              print(&quot;[INFO] closing...&quot;)
              self.stopEvent_2.set()
              self.vs.stop()
              self.root.quit()
      
         
      # here's the main window
      Mafenetre = tk.Tk()
      #set main window title
      Mafenetre.title(&quot;GUI&quot;)
      Mafenetre['bg']='white' # couleur de fond
      # get screen width and height
      wf1= Mafenetre.winfo_screenwidth()
      hf1= Mafenetre.winfo_screenheight()
      A = str(wf1)
      B = str(hf1)
      # set the dimensions of the screen 
      # and where it is placed
      
      w = 500 # width for the Tk root
      h = 500 # height for the Tk root
      # get screen width and height
      ws = Mafenetre.winfo_screenwidth() # width of the screen
      hs = Mafenetre.winfo_screenheight() # height of the screen
      # calculate x and y coordinates for the Tk master window
      x = (ws/2) - (w/2)
      y = (hs/2) - (h/2)
      # set the dimensions of the screen 
      # and where it is placed
      Mafenetre.geometry('%dx%d+%d+%d' % (w, h, x, y))
      # add test button to the main window
      reglage = tk.Button(Mafenetre, bd = '5',text=&quot;  PARAM  &quot;, bg='#c42034', fg='white',font= &quot;Helvetica&quot;, 12))
      reglage.pack(side=tk.TOP, padx=6,pady=35)
      camera = VideoStream(0).start()
      pba = PhotoBoothApp(camera)
      Mafenetre.mainloop()
  </code></pre>