如何在两个功能之间暂停?

时间:2017-10-12 16:36:46

标签: python function pause

如何在choice_f ()draw_f ()的功能之间暂停?

while keepGoing:
for event in pygame.event.get():
    if event.type==pygame.QUIT:
        keepGoing=False
    if event.type==pygame.KEYDOWN:
        if event.key==pygame.K_SPACE:
            choice_f()
#I want a pause here.
            draw_f()
    pygame.display.update()
pygame.quit()

非常感谢你的帮助。

2 个答案:

答案 0 :(得分:0)

如果我理解你的要求,你可以简单地使用time.sleep(n)来实现。

如下:

import time

while keepGoing:
for event in pygame.event.get():
if event.type==pygame.QUIT:
    keepGoing=False
    if event.type==pygame.KEYDOWN:
    if event.key==pygame.K_SPACE:
        choice_f()
        #Pause for 5 seconds Example.
        time.sleep(5)
        draw_f()
    pygame.display.update()
pygame.quit()

答案 1 :(得分:0)

#Everything is working. I did it.  

import time
while keepGoing:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            keepGoing=False
        if event.type==pygame.KEYDOWN:
        if event.key==pygame.K_SPACE:
            choice_f()
            pygame.display.flip()
            pygame.time.delay(1000))
            draw_f()
    pygame.display.update()
pygame.quit()