Вы можете использовать root.after(...)
.Ниже приведен пример кода:
# define a variable used to stop the image capture
do_image_capture = True
def capture_image():
if do_image_capture:
camera.capture(rawCapture, format='bgr', use_video_port=True)
# do whatever you want on the captured data
...
root.after(100, capture_image) # adjust the first argument to suit your case
capture_image()
Ниже приведен пример кода с использованием потока:
import threading
stop_image_capture = False
def capture_image():
for frame in camera.capture_continuous(rawCapture, format='bgr', use_video_port=True)
# do whatever you want on the capture image
....
if stop_image_capture:
break
t = threading.Thread(target=capture_image)
t.setDaemon(True)
t.start()