【发布时间】:2019-10-03 06:30:12
【问题描述】:
在下面的代码中,我在 Pygame 中得到了一个带有按钮的屏幕。现在我想点击按钮,然后random() 函数启动,5 秒后它从按钮开始返回屏幕,让我可以选择再次点击并再次调用随机函数。
def loop():
clock = pygame.time.Clock()
number = 0
# The button is just a rect.
button = pygame.Rect(300,300,205,80)
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# This block is executed once for each MOUSEBUTTONDOWN event.
elif event.type == pygame.MOUSEBUTTONDOWN:
# 1 is the left mouse button, 2 is middle, 3 is right.
if event.button == 1:
# `event.pos` is the mouse position.
if button.collidepoint(event.pos):
# Incremt the number.
number += 1
random()
loop()
pygame.quit()
【问题讨论】: