tcl_error in Tkinter when launching python IDLE from Cygwin
Asked Answered
S

2

5

I tried to launch IDLE from cygwin and I got the below error:

Traceback (most recent call last):
  File "/usr/bin/idle", line 5, in <module>
    main()
  File "/usr/lib/python2.7/idlelib/PyShell.py", line 1537, in main
    root = Tk(className="Idle")
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1764, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk,         sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

I can launch the IDLE from the idle.bat file as cygstart idle.bat.

I searched for an explanation of this error and could not find one. I have also added IDLE as an environmental variable in cygwin. When I do printenv, it shows up as an environmental variable. Just in case this was the problem, I tried two environmental variables:

idle=C:\Python27\Lib\idlelib\idle.bat PATH = cygdrive/c/Python27/Lib/idlelib

I also have the cygwin IDLE package installed.

What could be the problem?

Sakhuja answered 24/10, 2014 at 19:44 Comment(0)
R
7

try setting the DISPLAY environment variable

export DISPLAY=:0.0

and make sure you have a cygwin-x server running (i.e Xwin server)

you can add the export to your .bash_rc file so it is set every time you start cygwin.

Raguelragweed answered 24/10, 2014 at 21:58 Comment(4)
It gives me another error about couldn't connect to display "0:0" How do I make sure the cygwin-x server is running? Thanks @benSakhuja
if you have it installed, just open it by clicking the start menu and searching for Xwin Server. Note: you can close the popup and it is still running, at least on my boxes. If you don't have it installed you should head over to x.cygwin.com and read up on how to install it.Raguelragweed
The Xwin Server is running, however, there is still couldn't connect to display ":0.0". Any ideas?Modernism
UPD. The error is gone. I did nothing.Modernism
S
3

The answer provided by chaps completely solved my problem. (I'm on Windows 10.) I used the Cygwin installer ("Install from Internet" option) to update my existing Cygwin installation by selecting the "Full" (instead of the default "Pending") option from the dropdown menu at top left of the Cygwin installer, and installing only the packages xorg-server, xinit, xorg-docs, and xlaunch. (I'm not interested in any remote functionality, merely in using tkinter with python3 to do things like display filedialog controls.) I put a shortcut to xlaunch in my Taskbar and launched it with its default settings, then added export DISPLAY=:0.0 to my environment and ran the tkinter test suite. It worked perfectly.

Samuel answered 6/11, 2018 at 15:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.