title: Is there a way to draw a rect using after a function call using the Pygame library? after a button press
body: <p>I am building a little game that is similar to an old arcade game where you stack blocks. What I am trying to do is after every space key press the program would draw a block wherever in the screen i happen to hit the space key while the block is moving from left to right or vice versa. I managed to get the current coordinates wherever the block is after i hit the space key and use those to draw a new one, while the new block is moved up in the screen.  </p>
  
  <p>This is the print out to the console i am using to see what gets passed.</p>
  
  <pre><code>second space key pressed
  next_block() 228 660
  second space key pressed
  next_block() 11 600
  second space key pressed
  next_block() 18 540
  </code></pre>
  
  <pre><code>def game_loop():
      sq_x = 60
      sq_y = 660
      sq_change_x = 7
      bumped = True
      while bumped:
          for event in pygame.event.get():
              if event.type == pygame.QUIT:
                  pygame.quit()
                  quit()
                  sys.exit()
              if event.type == pygame.KEYDOWN:
                  if event.key == pygame.K_SPACE:
                      print("second space key pressed")
                      # pass the current coords to next_block()
                      next_block(sq_x, sq_y)
                      # moves the block -60 after every space bar key press
                      sq_y -= 60
  
          gamedisplay.fill(black)
          # draws the initial block that is positioned at the bottom of the window
          pygame.draw.rect(gamedisplay, blue_block, [sq_x, sq_y, 240, 60])
          # boundaries so the block only is animated within the window
          sq_x += sq_change_x
          if sq_x &gt; 360 or sq_x &lt; 0:
              sq_change_x = sq_change_x * -1
  
          game_background()
  
          pygame.display.update()
          clock.tick(60)
  </code></pre>
  
  <p>This is the function that is supposed to draw the rectangle after the key press, but it doesn't do anything to the screen....it doesn't draw anything.</p>
  
  <pre><code>def next_block(sq_x, sq_y):
      # gets called after the space key is press and draws a block at the given coords.
      pygame.draw.rect(gamedisplay, yellow_block, [sq_x, sq_y, 240, 60])
  
      print("next_block()", sq_x, sq_y)
  </code></pre>
  
  <p>can someone help me understand why this logic is not working? the function gets the coordinates but does not draw anything. This is just a little side project i am doing.</p>