-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Error] _tkinter.TclError: no display name and no $DISPLAY environment variable #4703
Comments
Know nothing about Linux system. Just found something may help
$ printenv grep DISPLAY
localhost:0.0 if not specified, try to add following code before your run PySimpleGUI or tkinter code. import os
if os.environ.get('DISPLAY','') == '':
print('no display found. Using :0.0')
os.environ.__setitem__('DISPLAY', ':0.0') Not for users for following code setting = os.environ.__getitem__('DISPLAY')
window = tk.Tk(screenName = setting) |
This didn't work. I got the following error: |
Ok, it looks like you use
Tried to Install Maybe you can modify the environment export DISPLAY=localhost:0.0 or import os
import PySimpleGUI as sg
if os.environ.get('DISPLAY','') == '':
os.environ.__setitem__('DISPLAY', ':0.0')
sg.Window(title="Hello World", layout=[[]], margins=(100, 50)).read(close=True) |
|
First, it's not issue about PySimpleGUI or tkinter, but Windows Subsystem for Linux. Follow steps in your WIN10, and it work on my WIN10 and not sure if it work for everyone for maybe different configuration of WIN10.
jason990420@DESKTOP-ST6UJK4:~$ python3 hello.py
Traceback (most recent call last):
File "hello.py", line 7, in <module>
sg.Window(title="Hello World", layout=[[]], margins=(100, 50)).read(close=True)
File "/home/jason990420/.local/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 8753, in read
results = self._read(timeout=timeout, timeout_key=timeout_key)
File "/home/jason990420/.local/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 8819, in _read
self._Show()
File "/home/jason990420/.local/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 8578, in _Show
StartupTK(self)
File "/home/jason990420/.local/lib/python3.8/site-packages/PySimpleGUI/PySimpleGUI.py", line 14746, in StartupTK
Window.hidden_master_root = tk.Tk()
File "/usr/lib/python3.8/tkinter/__init__.py", line 2270, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
jason990420@DESKTOP-ST6UJK4:~$ export DISPLAY=localhost:0.0
jason990420@DESKTOP-ST6UJK4:~$ python3 hello.py # hello.py
import PySimpleGUI as sg
sg.Window(title="Hello World", layout=[[]], margins=(100, 50)).read(close=True) |
OK , I am a newbie but I Using PyCharm in Windows 11 and SSH to Raspberry Pi and I was getting the above error...this code suggested by Jason above did the trick for me.. specifically I added this code to the very beginning of my code: if os.environ.get('DISPLAY','') == '': sg.Window(title="Hello World", layout=[[]], margins=(100, 50)).read(close=True) |
_tkinter.TclError: no display name and no $DISPLAY environment variable PySimpleGUI/PySimpleGUI#4703
Type of Issue (Enhancement, Error, Bug, Question)
Error
Operating System
Windows Subsystem for Linux (practically Linux in most cases)
PySimpleGUI Port (tkinter, Qt, Wx, Web)
tkinter (
PySimpleGUI
)Versions
Version information can be obtained by calling
sg.main_get_debug_data()
Or you can print each version shown in ()
Python version (
sg.sys.version
)3.9.6
PySimpleGUI Version (
sg.__version__
)4.47.0
GUI Version (tkinter (
sg.tclversion_detailed
), PySide2, WxPython, Remi)8.6.10
Your Experience In Months or Years (optional)
1 Years Python programming experience
2 Years Programming experience overall
Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine) Not really
Anything else you think would be helpful?
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
Detailed Description
Hello,
I am trying out PySimpleGUI, so I made a "Hello World" program (below). When I ran it, I got the following error:
_tkinter.TclError: no display name and no $DISPLAY environment variable
So I try the demo Hello World on GitHub. And I got the same thing. It seems any PySimpleGUI program I run raises that error.
Code To Duplicate
Screenshot, Sketch, or Drawing
Watcha Makin?
If you care to share something about your project, it would be awesome to hear what you're building.
The text was updated successfully, but these errors were encountered: