Advertisement
PsHegger

Webcam check on Linux

Mar 11th, 2011
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import time         # import time to let the program sleep a bit
  4. import thread           # import to create separated thread
  5. from Tkinter import *       # GUI imports
  6. import os.path as path      # import to check if a file exists
  7.  
  8. def check_state():
  9.     """ Method to check if the video camera is on """
  10.     global statelbl
  11.     while 1:
  12.         if path.exists("/dev/video0"):          # if the camera is on there's a file called video# in /dev
  13.             stateLbl.configure(text="on")
  14.             stateLbl.configure(foreground="green")
  15.         else:                       # the camera is off
  16.             stateLbl.configure(text="off")
  17.             stateLbl.configure(foreground="red")
  18.         time.sleep(.5)                  # wait a bit
  19.  
  20. abl = Tk()
  21. abl.title("Webcam")
  22. abl.resizable(width=False, height=False)
  23. Label(abl, text="The webcam is ").grid(column=1, row=1)
  24. stateLbl = Label(abl, text="...checking...")
  25. stateLbl.grid(row=1, column=2)
  26. thread.start_new_thread(check_state, ())            # start a separated Thread to check
  27. abl.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement