【发布时间】:2021-06-30 14:25:30
【问题描述】:
我创建了一个按钮类:
class MenuButton:
def __init__(self, font, size, text, pos, color):
self.font = font
self.size = size
self.text = text
self.pos = pos
self.color = color
def draw(self):
button_text = pygame.font.SysFont(self.font, self.size).render(self.text, True, self.color)
button_rect = button_text.get_rect()
button_rect.center = self.pos
screen.blit(button_text, button_rect)
mouse_pos = pygame.mouse.get_pos()
if button_rect.collidepoint(mouse_pos):
self.color = RED
而且我想在鼠标悬停时更改字体颜色,但显然,这与更改按钮颜色不同,因为我所做的没有奏效。有人知道当鼠标悬停在文本上时如何更改文本颜色? (我不知道我的错误是什么)
【问题讨论】:
标签: python button colors pygame