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

时间:2020-07-03 15:59:10

标签: python ubuntu tkinter

所以我试图在Windows 10上从Ubuntu命令行使用tkinter运行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

如果您使用的是matplotlib库,请使用以下问题:_tkinter.TclError: no display name and no $DISPLAY environment variable

但是,这个问题仅适用于使用tkinter库的人

1 个答案:

答案 0 :(得分:1)

除非下载外部软件,否则一个人不能在bash终端中运行活动GUI。以下教程是我如何解决该问题的方法:http://pjdecarlo.com/2016/06/xming-bash-on-ubuntu-on-windows-x11-window-system-running-from-windows-10-subsystem-for-linux.html

  1. 下载xming x服务器:适用于Windows操作系统的免费显示服务器,仅允许您从终端显示gui和其他奇特的东西:在这里找到它:https://xming.en.softonic.com/download,然后运行服务器并且它应该出现在任务栏的右下方

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

  3. 现在运行您的GUI! brandon@DESKTOP-V5LTF5T:~$ python3 MainApp.py