title: How to load multiple images in PyGame?
body: <p>I need to load around 200 images in pygame to be blitted at various points in my game. I tried writing a function for this but kept coming back with <code>NameError: name 'tomato' is not defined</code>.</p>
  
  <p>All of the image names are what the variable of the loaded image is stored under: <code>tomato = pygame.image.load("tomato.png")</code></p>
  
  <p>Would using an array be better, if so how would I do that?</p>
  
  <p>The code:</p>
  
  <pre><code>def load(image):
      imagename = image
      imagetitle = str(imagename)+".png"
      image = pygame.image.load(imagetitle)
      return image
  
  load("tomato")
  
  def blit_f(fruit):
      gamedisplay.blit(fruit,(0,0))
      pygame.display.update()
  
  fruitlist = []        
  
  running = False
  while not running:
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              running = True
  
          if event.type == pygame.MOUSEMOTION:
              mouse = pygame.mouse.get_pos()
              color = screen.get_at(mouse)
  
              if color == (209,0,0,255):
                  blit_f(tomato)
                  fruitlist.insert(0,"tomato")
  
          if event.type == pygame.MOUSEBUTTONDOWN:
  
              if fruitlist[0] == "tomato":
                  gamedisplay.blit(tomato,(0,0))
                  pygame.display.update()
  </code></pre>
  
  <p>The NameError occurs only when the condition leading to the blitting of <code>tomato.png</code> is met: when I hover over the tomato image i.e. color red</p>
  
  <p>If I write <code>load(tomato)</code> instead of with <code>""</code>, NameError comes up as soon as I run the code, and highlights <code>load(tomato)</code> instead of <code>gamedisplay.blit(tomato)</code> as for with <code>load("tomato")</code>.</p>