开发者

Python: interrupt execution with key and run again

开发者 https://www.devze.com 2023-01-17 21:49 出处:网络
how can I 开发者_运维问答interrupt python execution with a key and continue to run when the key is pressed 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

精彩评论

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