Python: interrupt execution with key and run again
how can I 开发者_运维问答interrupt python execution with a key and continue to run when the key is pressed again ?
thanks
If you're using pygame, you can check for the key event and use a boolean switch.
def check_pause(self):
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_p:
self.pause = not self.pause
Something like that, attached to
while True:
self.check_pause()
if self.pause:
continue
# Main loop of program goes here.
精彩评论