【发布时间】:2018-06-23 14:01:51
【问题描述】:
我最近安装了适用于 Windows 10 的 Ubuntu 应用,以便我可以将它用于上课。
我正在遵循一些神秘的分配指示来“试用 tkinter”。
我按照位于 here: How to install and use Tkinter in ubuntu / Debian / Linux mint 的说明在 Ubuntu 终端窗口中安装了包 python3-tk。
然后我执行
~$ 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
【问题讨论】:
-
情况不同,因为我没有使用 ssh。一切都在我自己的机器上。我更新了我的帖子以更好地澄清。可能会从该帖子中获得一些见解(已阅读多个相似的内容),但我不知道如何将这些帖子中的信息应用于我的情况。
-
好吧,冒着问显而易见的风险,您是否有一个名为
$DISPLAY的环境变量? -
当 tcl/tk for linux 尝试连接到 X 服务器时出现错误消息。我的猜测是你必须告诉 Ubuntu 这样做,或者告诉 tcl/tk 不要寻找一个。无论哪种方式我都不知道。 (前面问题的解决方案是告诉 matplotlib 不要寻找 X 服务器。)多说一些你实际做了什么。您应该直接运行 Python,而不是通过 IDLE。也许你做了前者,尽管有标签,因为我怀疑当 it 调用 tkinter.Tk() 时 IDLE 应该失败。
-
我使用 Linux 并且拥有
DISPLAY=:0。我可以在命令行DISPLAY=:0或export DISPLAY=:0中更改它。或者我可以把它放在文件.bashrc中,每次我登录时都会执行 - 所以我不必手动执行。
标签: ubuntu tkinter windows-10 xserver xming