Reputation: 161
I'm using tkinter for a project, when running the code I get the message
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_ tkinter.TclError: couldn't connect to display ":0"
echo $DISPLAY returns :0
I've tried export DISPLAY=:0 and export DISPLAY=:0.0 but it doesn't work.
I want to display the GUI on the screen of the laptop Im on(the answers regarding ssh on the forum seem unrelated).
I'm using ubuntu on windows. I have tried using both python3 and 2.7 but I get the same message.
Upvotes: 5
Views: 28226
Reputation: 1446
Note: WSL now supports Linux GUI apps natively
Previous answer in case you hit issues :
Using WSL on windows to develop tkinter applications you have two main options.
Develop the app with cross-platform development in mind, then run the application via MS-DOS. Using GitHub will help you deal with Line Endings This is the course I recommend (and I use), especially if you are using Python 3.4+ which includes pathlib.Path
Not recommended is to install an x-server on Windows, in which case Xming seems the easiest to get working. Once installed run :
sudo apt-get install x11-apps ... then export your display as you did before ...
export DISPLAY=:0
Test the installation by running an app like xcalc from within WSL ... sample image
xcalc
Here is a sample of a tkinter app running under Xming on WSL after i commented out the icon code ... [tkinter app on xming] 7
Running the app through MS-DOS is my recommendation, when I tested xming it didn't deal with ".ico" files. It is likely issues like this might hinder more complex applications. However if you do choose this route more info is available here.
Upvotes: 9
Reputation: 82
if your OS is linux
run this command :
sudo xhost
then you see this -> SI:localuser:<pc name>
then run this command :
sudo xhost -SI:localuser:<pc name>
Upvotes: 1