I am making a button in pygame where if I press down, something happens. This works, but only after I click the mouse about 5-10 times. It may be because I'm using the mouse on my computer and not an external mouse. Does anyone know how to fix this?
def button(x, y, width, height, ic, ac, action=None):
mouse = pygame.mouse.get_pos()
# print(mouse)
if x + width > mouse[0] > x and y + height > mouse[1] > y:
pygame.draw.rect(screen, ac, (x, y, width, height), 0)
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN and action is not None:
if action == 'play':
game_loop()
elif action == 'quit':
pygame.quit()
quit()
else:
pygame.draw.rect(screen, ic, (x, y, width, height), 0)