'Change mouse cursor to hand pygame [duplicate]
Is there a way to change the mouse cursor from an arrow to a hand in pygame? I've made a button in pygame, and have it changing colors when the mouse hovers over it, but I would like the cursor to change to a hand. He're what I have so far:
class Button(pygame.sprite.Sprite):
def __init__(self, width, height, centerx, centery, text):
"""Initialize the button"""
self.image = pygame.Surface((width, height))
self.image.fill(COLORS["light-blue"])
self.rect = self.image.get_rect()
self.rect.centerx = centerx
self.rect.centery = centery
self.font = pygame.font.Font('clear-sans.medium.ttf', self.rect.height-4)
self.text = self.font.render(text, True, COLORS["black"])
self.text_rect = self.text.get_rect()
self.clicked = False
def update(self):
"""Update the button"""
self.text_rect.center = self.rect.center
def draw(self, screen):
"""Draw the button on the screen"""
clicked = False
mouse_pos = pygame.mouse.get_pos()
if self.rect.collidepoint(mouse_pos):
self.image.fill(COLORS["blue"])
if pygame.mouse.get_pressed()[0] == 1 and self.clicked is False:
self.clicked = True
else:
self.image.fill(COLORS["light-blue"])
if pygame.mouse.get_pressed()[0] == 0:
self.clicked = False
screen.blit(self.image, self.rect)
screen.blit(self.text, self.text_rect)
return self.clicked
I know how to change the cursor image, but I wondered if there was a built-in way in pygame to change the cursor to a hand without making a new sprite for it.
Solution 1:[1]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CheckerPhil |
