title: Pygame: Checking if button is pressed
body: <p>I'm working on the start menu for my game in python using pygame, I made a function that detects if the mouse pressed on the position of each button and if it does, it changes the value of a boolean asigned to said button. However the boolean values are not changing.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import pygame
  import sys
  import sqlite3 as lite
  
  # questions
  option_1 =  option_2 =  option_3 =  option_4 = ''
  
  # misc
  initial_pos = 220
  event_i = False
  event_g = False
  event_t = False
  event_e = False
  
  ...
  
  # Button Settings
  button = pygame.image.load("src/trans-button.png")
  button = pygame.transform.scale(button, (display_width - 84, 70))
  
  button_start = button_tutorial = button_top10 = button_salir = button
  
  # Game Functions
  
  def checkSelection():
      # We get the mouse coordinates
      mouse_x, mouse_y = pygame.mouse.get_pos()
  
      # Then proceed to evaluate it's position in relation with the buttons
  
      if(mouse_x &gt;= 42 and mouse_x &lt;= button.get_width() + 42 and mouse_y &gt;= initial_pos and mouse_y &lt;= initial_pos + button.get_height()):
          event_i = True
      if(mouse_x &gt;= 42 and mouse_x &lt;= button.get_width() + 42 and mouse_y &gt;= initial_pos + button.get_height() + 25 and mouse_y &lt;= initial_pos + button.get_height()*2 + 25):
          event_g = True
      if(mouse_x &gt;= 42 and mouse_x &lt;= button.get_width() + 42 and mouse_y &gt;= initial_pos + button.get_height()*2 + 50 and mouse_y &lt;= initial_pos + button.get_height()*3 + 50):
          event_t = True
      if(mouse_x &gt;= 42 and mouse_x &lt;= button.get_width() + 42 and mouse_y &gt;= initial_pos + button.get_height()*3 + 75 and mouse_y &lt;= initial_pos + button.get_height()*4 + 75):
          event_e = True
  
  ...
  
  # Game Loop
  while not crashed:
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              crashed = True
          if event.type == pygame.MOUSEBUTTONDOWN:
              checkSelection()
              checkSelection()
  
      if event_i:
          print 'Begin'
      if event_e:
          print 'It should exit'
          crashed = True
  
      window.blit(background, (0,0))
      drawAll()
      pygame.display.update()
      clock.tick(60)
  
  #End Game
  pygame.quit()
  quit()
  sys.exit()
  </code></pre>
  
  <p>The '...' are jumps I made in the code to show you only the parts related to the issues.</p>
  
  <p>The position detection does work, I checked it using 'print' for debbuging.</p>
  
  <p>-- Update --</p>
  
  <p>Accidentally deleted the section where the button was defined.<br>
  Also a few typos I made when I returned the code to it's original state.</p>