【发布时间】:2014-04-16 00:05:25
【问题描述】:
我刚刚启动并运行了我的 Kali live USB,我想通过编写一些我在 Windows 盒子上编写的代码来熟悉系统。长话短说,我无法让一些非常基本的 tkinter 代码工作,所以我变得超级基本。事实证明,如果我是 root 或 sudo,我只能让它运行。见下文。
ben@kali:/usr/lib/python3.2$ python
Python 3.2.3 (default, Feb 20 2013, 14:44:27)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tkinter import *
>>> t = Tk()
No protocol specified
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "tkinter/__init__.py", line 1701, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldnt connect to display ":0.0"
>>>
ben@kali:/usr/lib/python3.2$ sudo python
Python 3.2.3 (default, Feb 20 2013, 14:44:27)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tkinter import *
>>> t = Tk()
>>>
正如你所看到的,当不以 root 身份运行 python 时,我得到错误,通过使用 sudo for python 突然 tkinter 工作(显然你看不到窗口,但它工作)。我对 linux 很陌生,真的不知道从哪里开始。我确实在 tkinter 文件夹上尝试了 chmod 777 ,但这似乎没有效果。任何想法都会非常有帮助。谢谢
【问题讨论】:
-
查看错误消息
couldnt connect to display ":0.0。这不是 Python 问题,而是 linux 问题。可以有多个显示器。可能是,变量 - 告诉使用哪个显示器 - 未在非 sudo 模式下设置。