Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tcl_error in Tkinter when launching python IDLE from Cygwin

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?

like image 350
makansij Avatar asked Oct 24 '14 19:10

makansij


2 Answers

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.

like image 89
chaps Avatar answered Sep 21 '22 07:09

chaps


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.

like image 26
Speaker-to-Animals Avatar answered Sep 25 '22 07:09

Speaker-to-Animals