6 python python-2.7 14.04 tkinter
当我尝试使用以下命令安装 tkinter 时:
sudo apt-get install python-tk
Run Code Online (Sandbox Code Playgroud)
我收到此消息,表示它已安装:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-tk is already the newest version.
The following package was automatically installed and is no longer required:
libjpeg62
Use 'apt-get autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
Run Code Online (Sandbox Code Playgroud)
当我想导入它时,我收到此消息错误:
begueradj@begueradj-darwin:~/begueradj# python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tkinter import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tkinter
>>>
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
小智 13
如果你运行的是 python ver 3.xx 你应该为 python3 安装 tkinter
sudo apt-get install python3-tk
Run Code Online (Sandbox Code Playgroud)
那对我有用。
要使用 Tkinter,您所需要做的就是导入一个模块:
Run Code Online (Sandbox Code Playgroud)import Tkinter或者,更常见的是:
Run Code Online (Sandbox Code Playgroud)from Tkinter import *
因此,只需将导入行更改为import Tkinter例如:
$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> Tkinter.TkVersion
8.6
>>>
Run Code Online (Sandbox Code Playgroud)
来源:https ://docs.python.org/2/library/tkinter.html#tkinter-modules
| 归档时间: |
|
| 查看次数: |
70227 次 |
| 最近记录: |