```
[root@localhost]# rpm -qa | grep tkinter
tkinter-2.7.5-58.el7.x86_64
```
但是在python解释器中依然找不到TKinter:
```
[root@localhost]# python
Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import TKinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named TKinter
```
更神奇的是在执行一个GUI脚本时,却没有提示说[No module named TKinter](),而是有以下报错:
```
[root@localhost]# ./gui.py
Traceback (most recent call last):
File "./gui.py", line 12, in <module>
root = Tkinter.Tk()
File "/usr/lib64/python2.7/lib-tk/Tkinter.py", line 1745, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
```
按照网上的办法,安装Xming,但是依然有报错:
```
[root@localhost]# ./gui.py
Traceback (most recent call last):
File "./gui.py", line 12, in <module>
root = Tkinter.Tk()
File "/usr/lib64/python2.7/lib-tk/Tkinter.py", line 1745, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display "localhost:0.0"
```
求解决办法!
先谢谢各位了
2 个解决方案
#1
python2 貌似是这个(k是小写)
import Tkinter
#2
你的系统是不是服务器版本,没有窗口界面的。需要窗口界面版本系统
#1
python2 貌似是这个(k是小写)
import Tkinter
#2
你的系统是不是服务器版本,没有窗口界面的。需要窗口界面版本系统