Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import time # import time to let the program sleep a bit
- import thread # import to create separated thread
- from Tkinter import * # GUI imports
- import os.path as path # import to check if a file exists
- def check_state():
- """ Method to check if the video camera is on """
- global statelbl
- while 1:
- if path.exists("/dev/video0"): # if the camera is on there's a file called video# in /dev
- stateLbl.configure(text="on")
- stateLbl.configure(foreground="green")
- else: # the camera is off
- stateLbl.configure(text="off")
- stateLbl.configure(foreground="red")
- time.sleep(.5) # wait a bit
- abl = Tk()
- abl.title("Webcam")
- abl.resizable(width=False, height=False)
- Label(abl, text="The webcam is ").grid(column=1, row=1)
- stateLbl = Label(abl, text="...checking...")
- stateLbl.grid(row=1, column=2)
- thread.start_new_thread(check_state, ()) # start a separated Thread to check
- abl.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement