title: How to add a click event for images in Pygame?
body: <p>I have the following code. Which basically gets all the images from the folder apps and the subfolders of it. My problem is that I am trying to add a click event to all of the images to do the same thing. Basically "<code>exec("apps/" + apps[app_count] + "/app.py"</code>)"</p>
  
  <pre><code># -*- coding: utf-8 -*-
  from pygame import *
  import os
  import pygame
  import time
  import random
  import sys
  
  _image_library = {}
  
  class SeedOS():
  
      def home(self):
          (width, height) = (240, 320)
          screen = pygame.display.set_mode((width, height))
          pygame.display.set_caption('Seed OS')
          pygame.font.init() 
          Font30 = pygame.font.SysFont('Arial', 30)
          WHITE = (255,255,255)
          BLACK = (0,0,0)
          screen.fill(WHITE)
          apps = os.walk("apps").next()[1]
          app_count = 0
          icon_width = 15
          icon_height = 0
          max_width = 155
          pygame.display.flip()
          while True:
              while app_count &lt; len(apps):
                  print apps[app_count]
                  image = pygame.image.load("apps/" + apps[app_count] + "/app.png").convert()
                  screen.blit(image, (icon_width, icon_height))
                  icon_width+=70
                  if icon_width &gt; max_width:
                      icon_width = 15
                      icon_height +=70
                  app_count += 1
              time2 = time.strftime('%H:%M:%S')
              pygame.display.flip()
              pygame.draw.rect(screen,BLACK,(0,290,240,30))
              clock = Font30.render(time2, False, WHITE)
              screen.blit(clock,(60,288))
              for event in pygame.event.get():
                  if event.type == pygame.QUIT:
                      pygame.quit()
                      sys.quit()
  
  phone = SeedOS()
  phone.home()
  </code></pre>
  
  <p>This is the part of the code that checks all of the things in the folder "apps" </p>
  
  <pre><code>while app_count &lt; len(apps):
                      print apps[app_count]
                      image = pygame.image.load("apps/" + apps[app_count] + "/app.png").convert()
                      screen.blit(image, (icon_width, icon_height))
                      icon_width+=70
                      if icon_width &gt; max_width:
                          icon_width = 15
                          icon_height +=70
                      app_count += 1
  </code></pre>
  
  <p>and appends all the images from each folder. I want on every icon click , execute it's "app.py" as in every app folders there are two files: "app.png" and "app.py".</p>