Apr-15-2021, 05:36 PM
(This post was last modified: Apr-15-2021, 05:36 PM by Nick_tkinter.)
Hello everyone.
I have a big code in tkinter with 14 files.In one of my files I control my camera and show the output inside a frame (in tkinter).
So ,I will show you the code below ,it is implemented with threads. I want to use threads, because other parts of my program sticks a little bit.
But the problem is that the frame for output of camera is flashing a little bit.I don't know if my code is correct,
because I create and start a thread every time.
Using threads in video_stream(.) (see below) , other parts of program doesn't stick ,but my frame for the camera output is a little bit flashing.
Code if file a.py:
This is a function of (for example a.py)
I can't show you the whole code ,is big and maybe you will get confused.
I just want to tell me if I create threads normally.
Thanks a lot.
I have a big code in tkinter with 14 files.In one of my files I control my camera and show the output inside a frame (in tkinter).
So ,I will show you the code below ,it is implemented with threads. I want to use threads, because other parts of my program sticks a little bit.
But the problem is that the frame for output of camera is flashing a little bit.I don't know if my code is correct,
because I create and start a thread every time.
Using threads in video_stream(.) (see below) , other parts of program doesn't stick ,but my frame for the camera output is a little bit flashing.
Code if file a.py:
This is a function of (for example a.py)
import PIL , cv2
from PIL import Image , ImageTk
from tkinter import *
from datetime import datetime
import threading
cap = cv2.VideoCapture(2)
def video_stream(label_frame):
ret , frame = cap.read()
if(not cap.isOpened() ):
return -1
elif(ret):
frame = cv2.flip(frame , 1)
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = PIL.Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image = img)
label_frame.imgtk = imgtk
label_frame.configure(image = imgtk)
thread_call_camera = threading.Thread(target=video_stream,args=(label_frame,))
thread_call_camera.start()
#label_frame.after(20 , video_stream , label_frame)In another file ,for example b.py ,I call: << value = video_stream(a frame I designed here) >>I can't show you the whole code ,is big and maybe you will get confused.
I just want to tell me if I create threads normally.
Thanks a lot.
