开发者

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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜