今天我想开始与Tkinter合作,但我遇到了一些问题.
Python 3.2 (r32:88445, Mar 28 2011, 04:14:07)
[GCC 4.4.5] 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>
File "/usr/local/lib/python3.2/tkinter/__init__.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
Run Code Online (Sandbox Code Playgroud)
那么如何配置我的Python 3.2以使用Tkinter?
通过 pyenv 安装的 Python 版本无法导入tkinter:
? python
Python 3.8.1 (default, Feb 29 2020, 11:45:59)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/factor/.pyenv/versions/3.8.1/lib/python3.8/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
>>>
Run Code Online (Sandbox Code Playgroud)
或者您可能会收到有关标头版本与二进制文件不匹配的消息:
DEPRECATION WARNING: The system version of Tk is deprecated …Run Code Online (Sandbox Code Playgroud) 我想在Ubuntu 14.04上运行python代码,但是当我执行它时,它会给我以下错误消息
Traceback (most recent call last):
File "main.py", line 2, in <module>
from tkinter import *
ImportError: No module named tkinter
Run Code Online (Sandbox Code Playgroud) 当尝试使用 Tkinter 标准库包或其相关功能(海龟图形使用turtle和内置 IDLE IDE)或使用将此作为依赖项的第三方库(例如显示使用 Matplotlib 的图形窗口)。
似乎即使不存在因隐藏标准库模块名称而引起的问题(对于尝试遵循教程并使用海龟图形的初学者来说,这是一个常见问题 -示例 1;示例 2;示例 3;示例 4),通常会发生标准库 Tkinter 无法工作的情况。这是一个大问题,因为许多初学者再次尝试遵循使用海龟图形的教程,并盲目地假设turtle标准库将会存在。
可能会报错:
作为ModuleNotFoundError: No module named 'tkinter'; 或ImportError具有相同消息的 ;或使用不同的大小写(我知道名称从Tkinter2.x 更改为tkinter3.x;这是一个不同的问题)。
类似地,但引用内部_tkinter模块,并显示带有注释的代码“如果失败,您的 Python 可能无法配置 Tk”;或者使用自定义错误消息“请安装 python-tk 包”或类似内容。
当尝试turtle专门使用时,出现“没有名为turtle的模块” ,或者上述错误之一。
当尝试使用 Matplotlib 显示绘图时;通常,这种情况会在尝试更改后端后发生,默认设置是为了避免尝试使用 Tkinter。
当 Tkinter 被记录为标准库的一部分时,为什么会出现这样的问题?如何添加或修复缺少的标准库功能?对于特定的 …
python ×4
tkinter ×4
installation ×1
macos ×1
pyenv ×1
python-2.7 ×1
python-3.x ×1
ubuntu-14.04 ×1