title: Draw a polygon when space bar is pressed - Pygame (Python 3.6)
body: <p>I have a problem with pygame: I'd like that when I press the spacebar appears a square but I'm surely making a mistake because it doesn't become visible every time I press the key and it appears for a frame. My idea is that the square goes up and then falls down when reachs the top of the screen. Can I do this with a while loop? Every correction is helpfull because I rarely code and I have only read a guide about pygame.</p>
  
  <pre><code>import pygame
  pygame.init()
  bianco=(255,255,255)
  nero=(0,0,0)
  rosso=(255,0,0)
  verde=(0,255,0)
  blu=(0,0,255)
  display=pygame.display.set_mode((800,600))
  pygame.display.set_caption("Prova")
  px = 400
  py = 360
  h=40
  lead_x_change = 0
  lead_y_change = 0
  axx = px
  axy = py-30
  uscita = False
  while not uscita:
      display.fill((86,170,239))
      main = pygame.draw.rect(display,rosso,[px,py,30,h])    
      pygame.draw.rect(display, verde,[0,400,800,800])
      px += lead_x_change
      py += lead_y_change
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              uscita = True
          if event.type == pygame.KEYDOWN:
              if event.key == pygame.K_RIGHT:
                  lead_x_change +=1
              if event.key == pygame.K_LEFT:
                  lead_x_change +=-1
              if event.key == pygame.K_SPACE:
                  pygame.draw.rect(display,rosso,[100,100,100,100])
  
          if event.type == pygame.KEYUP:
              if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
                  lead_x_change = 0
              #if event.key == pygame.K_SPACE:
              #    pygame.draw.rect(display, blu,[0,400,800,800])
      pygame.display.update()
      clock = pygame.time.Clock()
      clock.tick(175)
  pygame.quit()
  quit()
  </code></pre>
  
  <p>-------------- EDIT ----------------</p>
  
  <pre><code># - updates -
  
  player_rect.x += lead_x_change
  player_rect.y += lead_y_change
  
  if display_rect:
      red_rect.y -= 5
      if red_rect.y == 0:
          go_down = True
  if go_down:
      red_rect.y += 5
  </code></pre>
  
  <p>To get the red_square down I tried this, but I have probably misunderstood the advice... 
  I wrote in the object part <code>go_down = False</code> while in the updates part I added the code up here. The result is the same of the previous attempt without <code>go_down</code> variable</p>