what if I clicked on the button and I wanted to change the button's image by the image I used to Hover? something like the button will be changed to imageHover since its is clicked. Once clicked, the image of the button should be the imageHover. It is like an indication that among all the buttons, it is the button clicked already. Help :( tysm
def choices(x, y, w, h, image, imageOn, action=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed() #py collects left middle right button; (1,0,0) -leftclick; (0,0,1)rightclick
rect = pygame.Rect(x, y, w, h)
on_button = rect.collidepoint(mouse)
if on_button: #panghover
screen.blit(imageOn, imageOn.get_rect(center=rect.center))
else:
screen.blit(image, image.get_rect(center=rect.center))
if on_button:
if click[0] == 1 and action!= None:
if action == "A":
pygame.quit()
quit()
elif action == "B":
pygame.quit()
quit()
elif action == "C":
pygame.quit()
quit()
q1BG = pygame.image.load(os.path.join("Images/Quiz", "question1.png"))
q1A = pygame.image.load(os.path.join("Images/Quiz", "q1A.png"))
q1AHover = pygame.image.load(os.path.join("Images/Quiz", "q1Ahover.png"))
q1B = pygame.image.load(os.path.join("Images/Quiz", "q1B.png"))
q1BHover = pygame.image.load(os.path.join("Images/Quiz", "q1Bhover.png"))
q1C = pygame.image.load(os.path.join("Images/Quiz", "q1C.png"))
q1CHover = pygame.image.load(os.path.join("Images/Quiz", "q1Chover.png"))
submit = pygame.image.load(os.path.join("Images/Quiz", "submit.png"))
submitHover = pygame.image.load(os.path.join("Images/Quiz", "submithover.png"))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
screen.blit(q1BG, [0, 0])
choices(370, 225, 300, 50, q1A, q1AHover, "A") #x,y, width, height
choices(370, 285, 300, 50, q1B, q1BHover, "B")
choices(370, 350, 300, 50, q1C, q1CHover, "C")
choices(370, 450, 300, 50, submit, submitHover, "submit")
pygame.display.update()