Ubuntu: _tkinter.TclError: no display name and no $DISPLAY environment variable

Question:

So I’m trying to run a python GUI using tkinter from Ubuntu command line, on Windows 10, and get the following error:

brandon@DESKTOP-V5LTF5T:~$ python3 MainApp.py
Traceback (most recent call last):
  File "MainApp.py", line 14, in <module>
    root = tk.Tk()
  File "/usr/lib/python3.6/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

If you are using the matplotlib library then use this question: _tkinter.TclError: no display name and no $DISPLAY environment variable

However, this question is for people using the tkinter library only

Asked By: notMyName

||

Answers:

One cannot run active GUI’s inside a bash terminal unless they download external software. The following tutorial is how I found out how to solve this problem: http://pjdecarlo.com/2016/06/xming-bash-on-ubuntu-on-windows-x11-window-system-running-from-windows-10-subsystem-for-linux.html

  1. Download xming x server: A free display server for windows operating systems, simply allows you to display gui’s and other fancy things from terminals: This is where I found it: https://sourceforge.net/projects/xming/ , then run the server and it should appear in the lower right hand of the taskbar

  2. Run the following command from bash/ubuntu:
    brandon@DESKTOP-V5LTF5T:~$ export DISPLAY=localhost:0.0, this sets the DISPLAY variable to the local host of the newly installed xming x xerver.

  3. Now run your GUI! brandon@DESKTOP-V5LTF5T:~$ python3 MainApp.py

Answered By: notMyName
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.