I'm sure there are more pythonic ways for this, but here is a simple example:
button_x = 0 button_y = 0 newGameButton = pygame.image.load("images/newGameButton.png").convert_alpha() x_len = newGameButton.get_width() y_len = newGameButton.get_height() mos_x, mos_y = pygame.mouse.get_pos() if mos_x>button_x and (mos_x<button_x+x_len): x_inside = True else: x_inside = False if mos_y>button_y and (mos_y<button_y+y_len): y_inside = True else: y_inside = False if x_inside and y_inside:
Read more about the mouse in pygame , as well as the surface in pygame .
Also here is an example close to this.
source share