[英]How to exit the while true loop with esc for python
I tried many ways to exit the while true loop, but I can't.我尝试了很多方法来退出 while true 循环,但我不能。 My code looks like this.
我的代码看起来像这样。
import time
import cv2
while True:
print ("Loop working")
time.sleep(2)
c = cv2.waitKey(7) % 0x100
if c == 27 or c == 10:
break
You are using waitkey wrong, try like this:您使用的 waitkey 错误,请尝试这样:
c = cv2.waitKey(7) & 0xFF
if c == 27 or c == 10:
break
or simpler:或更简单:
if cv2.waitKey(7) & 0xFF in [10, 27]:
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.