python - 在pygame中悬停时更改矩形的边框
问题描述
我有一个矩形:
PlayButton = pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(324, 380, 354, 35))
我想让矩形的边框在用户将鼠标悬停在矩形上时将颜色变为红色
# Checks if the rectangle is hovered over
if PlayButton.collidepoint(pygame.mouse.get_pos()):
print ('mouse is over newGameButton')
谢谢
解决方案
Set a state variable when the the muose hover:
hover = PlayButton.collidepoint(pygame.mouse.get_pos())
Draw an additional pygame.draw.rect()
where the width
parameter is set:
e.g. red border with a thickness of 3
if hover:
pygame.draw.rect(screen, (255, 0, 0), pygame.Rect(324, 380, 354, 35), 3)
推荐阅读
- mysql - 使用 vanilla sql 代码与 upsert 相比是否有优势
- amazon-web-services - 如果我无法访问加密密钥,如何恢复 RDS 实例?
- c# - 将包含带重音符号的单词的字符串列表添加到 RichEditText 框的正确方法
- python - Pandas:使用 apply 创建 2 个新列
- linux - 查找缓冲区的起始地址。缓冲区溢出
- ansible - 可以递归地从目录中查找最新文件
- react-native - React Native - iOS 发布构建失败
- javascript - 按列计算无序列表
- python-3.x - 如何重定向 QProcess 标准输出
- javascript - 打字稿:TS编译器不接受使用布尔类型