I have this sort of code:
width = 100
height = 50
gameDisplay.blit(button, (width, height))
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP and event.button == 1:
# replace the button's image with another
Is there any function or something that would let me replace the image with another?
To show changes on screen use
pygame.display.update()
.Your code should look like this
You cannot 'replace' anything you've drawn. What you do is that you draw new images over the existing ones. Usually, you clear the screen and redraw your images every loop. Here's pseudo-code illustrating what a typical game loop looks like. I'll use screen as variable name instead of gameDisplay, because gameDisplay goes against PEP-8 naming convention.
For your code you probably should do something like this:
If you only want to update the area where your image is you could pass rect inside the update method,
pygame.display.update(rect)
.