'Pygame create colored button using mask [duplicate]

I'm working on a pygame project and i need to create a button that changes color when hovered. I can't just use 2 images (one with the normal color and one with the hovered one) because i want to have a smooth transition between the 2 colors over a few frames. I could create all the images but it wouldn't be a very efficient method at all. So i got the idea of using an alpha mask like this one for the quit button:

alpha mask of the quit button

Where white mean the color with full opacity and black means 0 opacity. To display my button, i wanted to create a surface of the same size as the mask, fill it with the current button color, and then use my image as the alpha mask like in this example:

mask = pygame.image.load("quit.png").convert()
button = pygame.surface(mask.get_size())
button.fill(ButtonColor)
---Here goes the part where i use my mask as the alpha for my button---
screen.blit(button, ButonPosition)

But i searched the pygame doc and it seams that i can't set per-pixel alpha. So i wanted to know if you had a solution, or an alternative idea to make my button.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source