问题
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
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
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.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