title: Pygame buttons not working
body: <p>I have created some sort of menu navigation system in my game. All the screens are blitted in. The "Play" and "Quit" and "Controls" button works just fine but when I try to press menu from the controls screen, nothing happens. On the controls screen, you can faintly see the first menu screen from before. That might be the problem. I think that as the return to menu button is over the previous controls page button, it somehow is pressing the controls button from before. The button and menu segment of my code will be pasted here and the full thing will be pasted in a pastebin.</p>
  
  <pre><code>def text_to_button(msg,color,buttonx,buttony,buttonwidth,buttonheight,size = "small"):
  textSurf, textRect = text_objects(msg,color,size)
  textRect.center = ((buttonx + buttonwidth/2)), buttony+(buttonheight/2)
  gameDisplay.blit(textSurf, textRect)
  
  def button(text,x,y,width,height,inactive_color,active_color,size = "small",action = None):
  cur = pygame.mouse.get_pos()
  click = pygame.mouse.get_pressed()
  #print(click)
  if x + width &gt; cur[0] &gt; x and y + height &gt; cur[1] &gt; y:
      pygame.draw.rect(gameDisplay, active_color,(x,y,width,height))
      if click[0] == 1 and action != None:
          if action == "quit":
              pygame.quit()
              quit()
          if action == "controls":
              game_controls()
  
          if action == "play":
              gameLoop()
          if action == "main":
              game_intro()
  
  else:
      pygame.draw.rect(gameDisplay, inactive_color,(x,y,width,height))
  text_to_button(text,black,x,y,width,height,size)
  
  def game_controls():
  gcont = True
  while gcont:
      gameDisplay.blit(cont,(0,0))
  
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              pygame.quit()
              quit()
  
  
      button("Play",150,500,100,50,white,gray,"small",action = "play")
      button("Main Menu",320,500,150,50,white,gray,"tiny", action = "main")
      button("Quit",550,500,100,50,white,gray,"small", action = "quit")
  
  
      pygame.display.update()
      clock.tick(15)
  
  def game_intro():
  intro = True
  while intro:
  
      gameDisplay.blit(imggg,(0,0))
  
      button("Play",150,500,100,50,white,gray,"small",action = "play")
      button("ControLs",320,500,150,50,white,gray,"tiny", action = "controls")
      button("Quit",550,500,100,50,white,gray,"small", action = "quit")
  
  
  
  
  
  
  
      pygame.display.update()
      clock.tick(15)
  
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              pygame.quit()
              quit()
      if event.type == pygame.KEYDOWN:
          if event.key == pygame.K_p:
              intro = False
  </code></pre>
  
  <p>Full Code: <a href="https://pastebin.com/jrd82gkJ" rel="nofollow noreferrer">https://pastebin.com/jrd82gkJ</a></p>