import pygame pygame.init() WIDTH, HEIGHT = 500, 500 display = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Player Click Detection") class Player: def __init__(self): self.rect = pygame.Rect(100, 100, 100, 100) def draw(self, surface): pygame.draw.rect(surface, (255, 0, 0), self.rect) player = Player() running = True while running: display.fill((0, 0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.MOUSEBUTTONDOWN: if player.rect.collidepoint(pygame.mouse.get_pos()): print("Mouse clicked on the Player") if event.type == pygame.MOUSEBUTTONUP: if player.rect.collidepoint(pygame.mouse.get_pos()): print("Mouse released on the Player") player.draw(display) pygame.display.flip() pygame.quit()