Ubuntu:_tkinter.TclError:没有显示名称,也没有 $DISPLAY 环境变量

not*_*ame 1 python ubuntu tkinter

因此,我尝试在 Windows 10 上使用 tkinter 从 Ubuntu 命令行运行 python GUI,并收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

如果您正在使用该matplotlib库,请使用以下问题:_tkinter.TclError:没有显示名称并且没有 $DISPLAY 环境变量

但是,这个问题tkinter仅适用于使用图书馆的人

not*_*ame 5

除非下载外部软件,否则无法在 bash 终端内运行活动 GUI。以下教程是我如何找到解决此问题的方法:http://pjdecarlo.com/2016/06/xming-bash-on-ubuntu-on-windows-x11-window-system-running-from-windows- 10-Linux 子系统.html

  1. 下载 xming x server:一个用于 Windows 操作系统的免费显示服务器,只允许您从终端显示 gui 和其他奇特的东西:这是我找到它的地方: https: //sourceforge.net/projects/xming/,然后运行服务器,它应该出现在任务栏的右下角

  2. 从 bash/ubuntu: 运行以下命令 brandon@DESKTOP-V5LTF5T:~$ export DISPLAY=localhost:0.0,这会将 DISPLAY 变量设置为新安装的 xming x xerver 的本地主机。

  3. 现在运行你的图形用户界面!brandon@DESKTOP-V5LTF5T:~$ python3 MainApp.py