0

I'm using Tkinter and running into the next error:

Traceback (most recent call last):
File "TKtest.py", line 3, in <module>
    master = tk.Tk()
  File "/usr/lib/python3.7/tkinter/__init__.py", line 2023, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

My code is as simple as it gets:

import tkinter as tk

master = tk.Tk()

Note: I am not using SSH. This is just my Pi 4 connected via HDMI to the 7 inch touchscreen. Note2: I already tried to set DISPLAY:0.0 but this doesn't solve the problem: echo $DISPLAY also gives :0.0

How do I solve this error?

  • Are you running it on the desktop? What happens if you run DISPLAY=:0 ~/TKtest.pi ? – Dougie Dec 5 '19 at 20:20
  • Permission denied, tried multiple files – StevenCellist Dec 5 '19 at 20:25
  • OK Try DISPLAY=:0 python3 ~/TKtest.py – Dougie Dec 5 '19 at 22:29
  • Tried that, as well as sudo DISPLAY=:0 python3 /TKtest.py (need acces to GPIO) This returns me with: couldn't connect to display ":0" – StevenCellist Dec 5 '19 at 23:00

Your Answer

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

Browse other questions tagged or ask your own question.