title: raspberry pi touch screen - Pygame.error: video system not initialized
body: <p>I am using a block of code from a <a href="http://jeremyblythe.blogspot.co.uk/2014/09/raspberry-pi-pygame-ui-basics.html" rel="nofollow">website</a> here is the section I am using: </p>
  
  <pre><code>import pygame
  from pygame.locals import *
  import os
  from time import sleep
  import RPi.GPIO as GPIO
  
  #Setup the GPIOs as outputs - only 4 and 17 are available
  GPIO.setmode(GPIO.BCM)
  GPIO.setup(4, GPIO.OUT)
  GPIO.setup(17, GPIO.OUT)
  
  #Colours
  WHITE = (255,255,255)
  
  os.putenv('SDL_FBDEV', '/dev/fb1')
  os.putenv('SDL_MOUSEDRV', 'TSLIB')
  os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen')
  
  pygame.init()
  pygame.mouse.set_visible(False)
  lcd = pygame.display.set_mode((320, 240))
  lcd.fill((0,0,0))
  pygame.display.update()
  
  font_big = pygame.font.Font(None, 50)
  
  touch_buttons = {'17 on':(80,60), '4 on':(240,60), '17 off':(80,180), '4 off':(240,180)}
  
  for k,v in touch_buttons.items():
      text_surface = font_big.render('%s'%k, True, WHITE)
      rect = text_surface.get_rect(center=v)
      lcd.blit(text_surface, rect)
  
  pygame.display.update()
  
  while True:
      # Scan touchscreen events
      for event in pygame.event.get():
          if(event.type is MOUSEBUTTONDOWN):
              pos = pygame.mouse.get_pos()
              print pos
          elif(event.type is MOUSEBUTTONUP):
              pos = pygame.mouse.get_pos()
              print pos
              #Find which quarter of the screen we're in
              x,y = pos
              if y &lt; 120:
                  if x &lt; 160:
                      GPIO.output(17, False)
                  else:
                      GPIO.output(4, False)
              else:
                  if x &lt; 160:
                      GPIO.output(17, True)
                  else:
                      GPIO.output(4, True)
      sleep(0.1)
  </code></pre>
  
  <p>When I run it (with root privileges) I get this error:</p>
  
  <pre><code>  File "touchscreen.py", line 20, in &lt;module&gt;
      pygame.mouse.set_visible(False)
  pygame.error: video system not initialized
  </code></pre>
  
  <p>I am trying to create a simple button interface on a raspberry pi touchscreen for my project, any working soloution would be welcomed. It does not matter to me if this code is repaired alternative code would be equally valid.</p>
  
  <p>Thank you, </p>
  
  <p>Matthew Wood</p>