Mar-21-2021, 09:30 AM
OK.I will describe it simply.I want to push a button and enable camera inside a frame ,when I push it again I want to disable camera.
So ,I have a file(eg: file b.py) and I call function camera_status(...) which is inside (eg: file a.py),the button is inside camera_status(...) and when I push it in order to enable/disable the camera, I have to call the same function,because inside this function I enable/disable camera (generally control camera).
Am I clear?
The problem is that the light of my laptop's camera is enabled ,but the frame doesn't show anything.
My code is big and have a lot of files.I made 2 files (file a and b),just to see what I mean and what I want in order to help you understand.
file a.py:
Thanks in advance.
So ,I have a file(eg: file b.py) and I call function camera_status(...) which is inside (eg: file a.py),the button is inside camera_status(...) and when I push it in order to enable/disable the camera, I have to call the same function,because inside this function I enable/disable camera (generally control camera).
Am I clear?
The problem is that the light of my laptop's camera is enabled ,but the frame doesn't show anything.
My code is big and have a lot of files.I made 2 files (file a and b),just to see what I mean and what I want in order to help you understand.
file a.py:
from tkinter import * #from GUI_camera import video_stream import cv2 , PIL from PIL import Image,ImageTk cap = cv2.VideoCapture(0) def camera_status(root , mode): # control camera camera_frame = LabelFrame(root , width = 663 , height = 528) camera_frame.place(x = 844 , y = 300) if(mode): ret , frame = cap.read() if(ret): frame = cv2.flip(frame , 1) cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA) img = PIL.Image.fromarray(cv2image) imgtk = ImageTk.PhotoImage(image = img) camera_frame.imgtk = imgtk camera_frame.configure(image = imgtk) print("Camera is enabled") #enable_camera_logo = Image.open("logo/enable_camera.png") else: print("camera is disabled") #enable_camera_logo = Image.open("logo/disable_camera.png") pass #enable_camera_logo = enable_camera_logo.resize( (75 , 30) , resample = 0) #enable_camera_image = ImageTk.PhotoImage(enable_camera_logo) camera_button = Button(root , text = "Control camera") # see in the terminal the output message camera_button.config(command = lambda: camera_status(root , mode) ) #camera_button.image = enable_camera_image camera_button.place(x = 840 , y = 250) mode = not modefile b.py:
from tkinter import * from a import camera_status root = Tk() root.geometry("1800x1100") root.after(1 , camera_status(root , False) ) root.mainloop()Can you help me?
Thanks in advance.