0
votes

I'm working with pygame to try and produce a visual Blackjack game. I'va had a look around for past hour or so, and I can't seem to find anything that does what I'm looking for. I need to update the display (named screen in my code) so that the user can navigate through the menu with ease. the function below is the product of all that I've read up on and, when applied and ran with the necessary button, it only changes the colour of the "Blackjack Blast" text whilst the mouse button is being held down.

def update_window():
      textsurface = Font1.render('BlackJack Blast!', True, e_m_lighter)
      screen.blit(textsurface,(106,100))
      pygame.display.update()

Could anyone offer any assistance as to how I can get the display to permanently update with a single button press?

1
Please consider adding a code sample, or revising the one you posted in this question. As it currently stands, its formatting and scope make it hard for us to help you; here is a great resource to get you started on that. Good luck with your code! - Reblochon Masque
better learn OOP (Object-Oriented Programing) and then you can create class Button which will remeber state. Your update_window() change text but it doesn't remeber it so next time mainloop will draw old version. - furas
see example button-click-cicle-color - it remebers current color in self.index so after click it still displays correct color. - furas

1 Answers

0
votes

I can't see your code so I will improvise.

You have to use variable which will remeber that you clicked buttom (ie. clicked = False) and split code into two part - one will change clicked, second will draw different button depend on value in clicked

# set on start (before mainloop)

clicked = False

# executed when you click in button

def update_window():
  global clicked
  clicked = True    

# in main loop when you draw button

if clicked
  textsurface = Font1.render('BlackJack Blast!', True, e_m_lighter)
else:
  textsurface = Font1.render('BlackJack Blast!', True, NORMAL_COLOR)

screen.blit(textsurface,(106,100))
pygame.display.update()

Or you can use variable to keep current image

# set on start (before mainloop)

normal_text = Font1.render('BlackJack Blast!', True, NORMAL_COLOR)
clicked_text = Font1.render('BlackJack Blast!', True, e_m_lighter)

current_text = normal_text

# executed when you click in button

def update_window():
  global current_text
  current_text = clicked_text

# in main loop when you draw button

screen.blit(current_text, (106,100))
pygame.display.update()