Windows 10 内的 Ubuntu 中的 tkinter。错误:“没有显示名称,也没有 $DISPLAY 环境变量”

2024-04-19

我最近安装了适用于 Windows 10 的 Ubuntu 应用程序,以便我可以在课堂上使用它。

我正在遵循一些神秘的作业指示来“尝试 tkinter”。

我按照位于 Ubuntu 终端窗口中的说明安装了包 python3-tk这里:如何在 ubuntu / Debian / Linux mint 中安装和使用 Tkinter http://www.techinfected.net/2015/09/how-to-install-and-use-tkinter-in-ubuntu-debian-linux-mint.html.

然后我执行

~$ python3

结果

Python 3.5.2 (default, Aug 18 2017, 17:48:00)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

然后执行以下命令:

>>> import tkinter
>>> tkinter.Tk()

由此产生的错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/tkinter/__init__.py", line 1871, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, 
wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

Solved:

注意:这是在 Windows 10 中使用 Ubuntu 应用程序时的情况

Install 适用于 Windows 的 Xming X 服务器 https://sourceforge.net/projects/xming/?source=typ_redirect.

安装过程中可以选择将显示设置为 0。

添加行export DISPLAY=:0; to .bashrc正如建议的那样。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Windows 10 内的 Ubuntu 中的 tkinter。错误:“没有显示名称,也没有 $DISPLAY 环境变量” 的相关文章

随机推荐