我在Raspberry Pi 2上有一个python脚本,如果在任何时候我想打断一个循环buttonpressed=True
类似于:
while True:
try:
do_something_pythonic()
except buttonpressed=True:
break
答案 0 :(得分:2)
while not self.button_pressed:
do_pythonic()
...
def OnButtonPress(self,evt):
self.button_pressed = True