title: Display GUI on Raspberry Pi without startx
body: <p>I'm currently playing with my brand-new raspberry with adafruit's <code>touch-tft</code> and raspberry Cam.</p>
  
  <p>I noticed, if I run <code>raspivid -p</code>, it displays the preview in a frame on top of the bash.</p>
  
  <p>How can I create an application (java, python, c++(preferred)) to display a GUI without having to <code>startx</code>?</p>
  
  <p>I'd love to use adafruit's <code>touch-tft</code> for a project, but <code>startx</code> needs a lot of resources. Of course it would be cool to have the touch-functionality too.</p>
  
  <p>Edit:</p>
  
  <p>Maybe I expressed myself a little bit confusing: I would like to create an application that doesn't need startx but has some kind of GUI.</p>
  
  <p>The answers below aren't 100% ready to go but they pointed me to the right direction. Since I saw many similar questions I will try to give a step-by-step solution:</p>
  
  <ol>
  <li><p>Setup your raspberry with adafruit's TFT: <a href="https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/overview" rel="nofollow">https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/overview</a>
  (you don't have to replace the TFT with HDMI as standart display)</p></li>
  <li><p>be sure <code>FRAMEBUFFER=/dev/fb1 startx</code> is running correctly on the TFT screen, I have my TV plugged in the HDMI port, this way I can use the bash on the TV screen and run x on the TFT</p></li>
  <li><p>Follow this tutorial to create your first pygame: <a href="http://www.pygame-doku.laymaxx.de/tut/intro/intro.html" rel="nofollow">http://www.pygame-doku.laymaxx.de/tut/intro/intro.html</a>
  (you can just copy&amp;paste, <code>wget ball.gif</code>)</p></li>
  <li><p>Insert this 2 lines at the beggining: (github.com/notro/fbtft/wiki/Pygame)</p>
  
  <pre><code>import os
  os.environ["SDL_FBDEV"] = "/dev/fb1"
  </code></pre></li>
  <li><p>If you want to test the touch-screen to, you can change Line 15:
  From:</p>
  
  <pre><code>if event.type == pygame.QUIT: sys.exit()
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>if event.type == pygame.MOUSEBUTTONDOWN: sys.exit()
  </code></pre>
  
  <p>This will exit the application if you touch the screen</p></li>
  <li><p>Save file e.g. pygame1.py and execute with <code>$python pygame1.py</code></p></li>
  </ol>
  
  <p>You should now see a bouncing ball on your TFT while the HDMI output still displays the BASH on your TV (but it isn't active of course) touching the screen will exit the game if you completed step 6</p>
  
  <p>Why I'm doing this? This way you can display a simple GUI with e.g. buttons to do some action, like turn your lights on/off if you use your RPI for home-control.</p>