I've done a google search and searched through my two python beginner books to find how to do this. I assume it has to be a simple task. Basically, I'm working with pygame with python.
I want that if I click on the button1_image, it changes to button1select_image, right? And if you click on button2_image, it sets button1select_image back to button1_image, and button2_image changes to button2select_image.
So what I am wondering is if it is a simple if else statement or is it much more complicated. Obviously, the buttons will do something else later but I cannot find a tutorial on how to do something like this based on the click of the users mouse.
# Button Mouse Click Image Change
# Demonstrates changing from one button image to another based on click of mouse.
from livewires import games, color
games.init(screen_width = 281, screen_height = 500, fps = 50)
button1_image = games.load_image("button1.png", transparent = False)
button1 = games.Sprite(image = button1_image, x = 28,y = 18)
games.screen.add(button1)
button1select_image = games.load_image("button1select.png", transparent = False)
button1select = games.Sprite(image = button1select_image, x = 28,y = 18)
games.screen.add(button1select)
button2_image = games.load_image("button2.png", transparent = False)
button2 = games.Sprite(image = button2_image, x = 56,y = 18)
games.screen.add(button2)
button2select_image = games.load_image("button2select.png", transparent = False)
button2select = games.Sprite(image = button2select_image, x = 56,y = 18)
games.screen.add(button2select)
games.screen.mainloop()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…