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

半世苍凉 提交于 2021-02-05 10:38:06

问题


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


回答1:


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://xming.en.softonic.com/download , 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



来源:https://stackoverflow.com/questions/62718967/ubuntu-tkinter-tclerror-no-display-name-and-no-display-environment-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!