我试图让按钮在鼠标悬停在它上面时做出反应。我想让它稍微调整一下大小,所以我在 Pygame、Python 中给出了一个按钮效果。
rock_img = pygame.image.load('assets/rock_btn.png').convert_alpha()
scissor_img = pygame.image.load('assets/scissor_btn.png').convert_alpha()
paper_img = pygame.image.load('assets/paper_btn.png').convert_alpha()
ROCK = rock_img
SCISSOR = scissor_img
PAPER = paper_img
rock_button = button.Button(85, 50, rock_img, 0.1)
scissor_button = button.Button(90, 390, scissor_img, 6)
paper_button = button.Button(90, 230, paper_img, 7)
running = True
while running:
pygame.draw.line(screen, (0,0,0),
[295, 0],
[295, 500], 5)
pygame.display.update()
if rock_button.draw(screen):
print('Rock')
if scissor_button.draw(screen):
print("Scissor")
if paper_button.draw(screen):
print('Paper')
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.update()
pygame.quit()