title: Black window pygame
body: <p>I am writing a snake game with pygame but I am just prompted with a black window without any error.</p>
  
  <p>I checked similar problems and they incorrectly used the screen object. However this does not seem to be the case here, since it is only created once?</p>
  
  <p>Any idea what I am doing wrong? Since I am not given any error message I can't figure out why I am only shown a black screen. The key input events work just fine.</p>
  
  <pre><code>import pygame
  import random
  import sys
  
  
  # Define colors
  GRAY = (240, 240, 245)
  WHITE = (255, 255, 255)
  RED = (255, 0, 0)
  GREEN = (0, 255, 0)
  BLACK = (50, 50, 50)
  
  # Field size
  width = 400
  height = 400
  
  
  
  # Calculate the distance between two points
  def calculate_distance(x1, x2, y1, y2):
      return (x2 - x1)**2 + (y1 - y2)**2 ** 1/2
  
  # Draws a label showing the current score in the top mid of the window
  def draw_score_text(surface, text, font_size, x, y):
      font_name = pygame.font.match_font('arial')
      font = pygame.font.Font(font_name, font_size)
      text_surface = pygame.font.render(text, True, WHITE)
      text_rect = text_surface.get_rect()
      text_rect.midtop = (x, y)
      surf.blit(text_surface, text_rect)
  
  
  class Snake(pygame.sprite.Sprite):
  
      def __init__(self):
          pygame.sprite.Sprite.__init__(self)
          self.image = pygame.Surface((12,12))
          self.image.fill(WHITE)
          self.rect=self.image.get_rect()
          self.rect.center = (100,100)
          self.speedx=0
          self.speedy=0
          self.score=0
          self.tail=[]
  
      def update(self):
          if self.score == len(self.tail):
              self.tail.append((self.rect.x, self.rect.y))
          else:
              self.tail.append((self.rect.x, self.rect.y))
              self.tail.pop(0)
  
          self.rect.x += self.speedx
          self.rect.y += self.speedy
  
          keys = pygame.key.get_pressed()
  
          if(keys[pygame.K_RIGHT] and self.speedx &gt;=0):
              self.speedx = 10
              self.speedy = 0
          if(keys[pygame.K_LEFT] and self.speedx &lt;=0):
              self.speedx = -10
              self.speedy = 0
          if(keys[pygame.K_UP] and self.speedy &lt;=0):
              self.speedx = 0
              self.speedy = -10
          if(keys[pygame.K_DOWN] and self.speedy &gt;=0):
              self.speedx = 0
              self.speedy = 10
  
          if self.rect.left &gt;= width:
              self.rect.left = 1
  
          if self.rect.top &gt;= height:
              self.rect.top = 0
  
          if self.rect.bottom &lt;= 0:
              self.rect.bottom = height
  
          if self.rect.left &lt;= 0:
              self.rect.left = width
  
      def exit(self):
          for i in range(1, len(self.tail)):
              if dist(self.rect.x, self.rect.y, self.tail[i][0], self.tail[i][1]) &lt; 1:
                  sys.exit()
  
  class Food(pygame.sprite.Sprite):
      def __init__(self, x, y):
          pygame.sprite.Sprite.__init__(self)
          self.image = pygame.Surface((12,12))
          self.image.fill(RED)
          self.rect=self.image.get_rect()
          self.rect.center = (x, y)
  
  
  # Start dah game
  pygame.init()
  screen = pygame.display.set_mode([width,height])
  clock = pygame.time.Clock()
  running = True
  
  print("ok?")
  all_sprites = pygame.sprite.Group()
  player = Snake()
  food = Food(random.randrange(20, width - 20), random.randrange(20, height - 20))
  all_sprites.add(player)
  all_sprites.add(food)
  
  while running:
  
      clock.tick(3)
      #pygame.display.update()
      keys_pressed = pygame.event.get()
      print(keys_pressed)
      for i in keys_pressed:
          if i.type == pygame.QUIT:
              print("quit")
              running = False
      if pygame.sprite.collide_rect(player, food):
  
          food.kill()
          player.score += 1
          food = Food(random.randrange(20, width - 20), random.randrange(20, height - 20)) 
          all_sprites.add(food)
  
      all_sprites.update()
      screen.fill(BLACK)
      player.exit()
  
      for i in range(1, len(player.tail)):
          pygame.draw.rect(screen, WHITE, (player.tail[i][0], player.tail[i][2], 12, 12))
          #draw_score_text(screen, str(player.score), 18, width/2, 10)
          all_sprites.draw(screen)
          pygame.display.flip()
  
  
  pygame.quit()
  </code></pre>