You can use pygame to handle events like these:
import pygame
(width, height) = (400, 250)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Title')
screen.fill((255,255,255))
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
# your code here
if event.type == pygame.QUIT:
running = False
You can also control the number of times pygame checks if the mouse button is pressed down (called FPS if you are not familiar with game terminology):
import pygame
(width, height) = (400, 250)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Title')
screen.fill((255,255,255))
pygame.display.flip()
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
# your code here
if event.type == pygame.QUIT:
running = False
clock.tick(30) # capped at 30 fps