I am trying to run this piece of code. But the problem is it never comes out of the loop.I am able to close the window but it pop back again I don't know why is happening? is it the problem with my installations or any error.
python version:3.6 opencv version:4.2.0.34
import numpy as np
from PIL import ImageGrab
import cv2
import time
while(True):
printscreen = np.array(ImageGrab.grab(bbox=(0,40,800,640)))
last_time = time.time()
print('loop took {} seconds'.format(time.time()-last_time))
cv2.imshow('window',cv2.cvtColor(printscreen, cv2.COLOR_BGR2RGB))
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break