pygame mouse code example
Example 1: pygame detect click
while ...
ev = pygame.event.get()
for event in ev:
if event.type == pygame.MOUSEBUTTONUP:
pos = pygame.mouse.get_pos()
clicked_sprites = [s for s in sprites if s.rect.collidepoint(pos)]
Example 2: pygame get mouse position
x,y = pygame.mouse.get_pos()
Example 3: pygame mouse pos
pygame.mouse.get_pos()
get the mouse cursor position
get_pos() -> (x, y)
Returns the x and y position of the mouse cursor.
The position is relative to the top-left corner of the display.
The cursor position can be located outside of the display window,
but is always constrained to the screen.