-1

Hi guys I want to create a basic GUI with TKinter.

This is my code

from tkinter import*
import tkinter.font

win =Tk()
win.title("Test")
myFont = tkinter.font.Font( family = 'Helvetica', size = 12, weight = 'bold')

def ledToggle():

        print("Hello World")


button1 = Button(win,text ='Test', font = myFont,command = ledToggle, bg='bisque2$
button1.grid(row=0,column=1)

I get this error message:

   Traceback (most recent call last):
  File "gui.py", line 4, in <module>
    win =Tk()
  File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
  • Why do you have to run startx manually, is your desktop environment broken or incomplete? And what kind of display we are talking about? HDMI? – Dmitry Grigoryev Jun 17 at 9:03
  • @DmitryGrigoryev do you have any ideas for me? – IT_Geek_Oz Jun 17 at 10:23
  • Its connected with LVDS not HDMI – IT_Geek_Oz Jun 17 at 11:05
  • How are you launching this program? Seems like you're doing it from a non-graphical context where there is no display defined... – Brick Jun 17 at 13:02
  • this question is not related to the RPi .... it is a linux or python programming question – jsotola Jun 17 at 13:17
2

this error usually happens when you access the RPI via SSH, you could run:

export DISPLAY=0:0

or add it to your bashrc if you want it to be perminantly excuted on every therminal run and ssh connection.

EDIT (a great suggestion by roger-jones):

you can also set the variable by prefixing it to the command: DISPLAY=0:0 python gui.py.

If you SSH with PuTTY you can also add the DISPLAY to the environment at "Connection">"Data">"Environment Variables"

if your not satisfied, check out similar errors as yours: link

  • For completeness you may want to add that you can also set the variable by prefixing it to the command: DISPLAY=:0 python gui.py. If SSHing in with PuTTY you can also add the DISPLAY to the environment at "Connection">"Data">"Environment Variables". – Roger Jones Jun 18 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.