import pygame from pygame.locals import * import sys pygame.init() display = pygame.display.set_mode((500,500)) FPS_CLOCK = pygame.time.Clock() class Player : def __init__(self): self.rect = pygame.draw.rect(display, (255,255,255), (100,100,100,100)) player = Player() while 1: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: if player.rect.collidepoint(pygame.mouse.get_pos()): print("Mouse clicked the rect/Player") if event.type == pygame.MOUSEBUTTONUP: if player.rect.collidepoint(pygame.mouse.get_pos()): print("Mouse released from the rect/Player") pygame.display.update() FPS_CLOCK.tick(30)