【发布时间】:2020-10-22 14:34:26
【问题描述】:
我创建了一个按钮功能,它可以工作,但如果我在屏幕上多次使用该功能,那么它只能在其中一个按钮上工作,我不知道为什么。
这是按钮功能的代码。
def button(x, y, w, h, action=None):
mx, my = pygame.mouse.get_pos()
for event in pygame.event.get():
if x + w > mx > x and y + h > my > y:
if event.type == pygame.MOUSEBUTTONDOWN:
action()
这是我尝试使用它的代码,第一个启动游戏循环的按钮有效,但应该退出的按钮没有
def game_intro():
intro = True
while intro:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.blit(bg_resize,(0,0))
gameDisplay.blit(play_resize,(100,150))
gameDisplay.blit(quit_resize,(575,150))
button(100,150,393,393,game_loop)
button(575,150,393,393,quit)
pygame.display.flip()
clock.tick(15)
【问题讨论】:
标签: python function button pygame