title: Is there a way to check if camera is connected without cap = cv2.videocapture
body: <p>I am making a program that checks if the camera is connected, and if so, Show the webcam footage, The problem is: The way i structured my program i cannot have <code>cap = cv2.videocapture()</code> for the time it takes the command to execute. This makes sabotages for the showframe function and makes it only show a frame every ~1 second. Is there a different way to check if the camera is connected rather than <code>cap = cv2.videocapture()</code> and <code>cap.isOpened()</code>?</p>
  
  <p>I also cannot have a while loop in my program because of the <code>root.mainloop</code> command for tkinter, However, if there is no way to check my camera status rather than <code>cap.isOpened()</code>, can i move the root.mainloop command somewhere where i can have a <code>while True</code> loop in my program?</p>
  
  <p>I've tried both Multiprocessesing and Threading with no further success. </p>
  
  <p>Heres some code:</p>
  
  <pre><code>from tkinter import *  # Import the tkinter module (For the Graphical User Interface)
  import cv2  # Import the cv2 module for web camera footage
  import PIL  # Import the pillow library for image configuration.
  from PIL import Image, ImageTk  # Import the specifics for Image configuration.
  
  print("[INFO] Imports done")
  
  width, height = 800, 600  # Define The width and height widget for cap adjustment
  RootGeometry = str(width) + "x" + str(height)  # Make a variable to adjust tkinter frame
  print("[INFO] Geometries made")
  
  ImageSource = 0
  cap = cv2.VideoCapture(ImageSource)  # First VideoCapture
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
  cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
  print("[INFO] Cap set")
  
  root = Tk()
  print("[INFO] Window made")
  
  root.title("Main Window")
  root.configure(background="white")
  root.geometry(RootGeometry)
  root.bind('&lt;Escape&gt;', lambda e: root.quit())
  lmain = Label(root)
  lmain.pack()
  print("[INFO] Configuration of cap done.")
  
  
  def ShowFrame():
      ok, frame = cap.read()
      if ok:
          print("[INFO] Show frame Initialized.")
  
          cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
          img = PIL.Image.fromarray(cv2image)
          imgtk = ImageTk.PhotoImage(image=img)
          lmain.imgtk = imgtk
          lmain.configure(image=imgtk)
          print("[INFO] After 10 initializing")
          lmain.after(10, ShowFrame)
          print("[INFO] Showed image")
  
      else:
          lmain.after(10, CheckSource)
  
  
  def CheckSource():
  
      print("[INFO] CheckSource Triggered.")
      cap = cv2.VideoCapture(ImageSource)
  
      if cap.isOpened():
          print("[INFO] [DEBUG] if Ok initialized")
          if cv2.waitKey(1) &amp; 0xFF == ord('q'):
              cv2.destroyAllWindows()
              cv2.waitKey(0)
              print("[WARNING] Exiting app after command")
  
          ShowFrame()
  
      else:
          print("[WARNING] No source found. Looking for source.")
          lmain.after(10, CheckSource)
  
  
  CheckSource()
  root.mainloop()
  print("[INFO] [DEBUG] Root.Mainoop triggered")
  </code></pre>
  
  <p>Any and all help would be very appreciated!</p>