title: Why does my pygame window freeze and crash?
body: <p>Whenever I try to run my program it freezes up and crashes. I'm not a master pygame coder, but I'm almost sure its something to do with my main loop. It's supposed to allow the user to move left and right using arrow keys. I've tried adding a clock and changing the size of the screen but that didn't work. Here is the code:</p>
  <pre><code>import pygame
  import sys
  import random 
  import time
  
  pygame.init()
  screen = pygame.display.set_mode((500,500))
  
  events = pygame.event.get()
  clock = pygame.time.Clock()
  
  x = 50
  y = 50
  
  game_over = False
  while not game_over:
      for event in events:
          if event.type != pygame.QUIT:
  
              if event.type == pygame.KEYDOWN:
                  if event.key == pygame.K_RIGHT:
                      x += 5
                  elif event.key == pygame.K_LEFT:
                      x -= 5
  
          else:
              sys.exit()
  
      
      screen.fill((0,0,0))
      pygame.draw.rect(screen, (255,255,255), (x,y,50,50))
      clock.tick(30)
      pygame.display.update()
  
  </code></pre>