Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sup,

  • I am simply trying to use Tkinter (a Python GUI creator) to create a GUI on my Raspberry Pi.
  • To start, I only want a GUI to show up on my screen. That's it!
  • The code DOES work on my PC
  • The code does NOT work on my Raspberry Pi

The entire script looks as follows:
(works on my PC, bringing up an empty GUI)

import Tkinter

root = Tkinter.Tk()

root.mainloop()

Trying to run the program in terminal as follows:

sudo python GUI.py

Produces the following error:

Traceback (most recent call last):

File "GUI.py", line 4, in root = Tkinter.Tk()

File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1817, in init

self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)

_tkinter.TclError: no display name and no $DISPLAY environment variable

Does anybody have any idea how I can resolve this issue? The error is produced under all of the following conditions:

  • Direct HDMI to computer monitor
  • DSI connection to touchscreen LCD
  • SSH on computer monitor

For reference, if I type the following into my terminal:

echo $DISPLAY


An empty string gets printed, so I believe therein lies the problem

The following commands don't work either, which might shed light on the problem:

sudo apt-get update

startx

share|improve this question
    
Why do you need sudo ? Are you calling script from ssh ? If yes, try setting DISPLAY varible by export DISPLAY=:0 and then running it. Hope it helps. – dhruvvyas90 Nov 19 '15 at 4:31
    
I am indeed running from SSH but I see the exact same error when I directly hardwire the Pi HDMI into a computer monitor and use a USB keyboard. – dsazer25 Nov 19 '15 at 21:35
1  
I like your idea and I tried it, but now I receive the error: _tkinter.TclError: couldn't connect to display ":0" – dsazer25 Nov 19 '15 at 21:36
    
That's because you're running it without x windows. Log in to raspbian desktop by startx and try doing it. – dhruvvyas90 Nov 19 '15 at 22:48
    
executing the command "startx" leads to an error as well. I started fresh on a brand new microSD card; everything worked fine until I started installing software packages, although I'm not sure which one led to the problem. If I figure it out I'll post which software package is the culprit! – dsazer25 Nov 23 '15 at 2:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.