我想导入Tkinter.但是,我收到一条错误,指出尚未安装Tkinter:
ImportError:没有名为_tkinter的模块,请安装python-tk包
我可以使用synaptic manager安装它(可以吗?),但是,我必须在我编程的每台机器上安装它.是否可以将Tkinter库添加到我的工作区并从那里引用它?
建议不要import *在Python中使用.
任何人都可以分享原因,以便我下次可以避免它吗?
我有一个简单的python脚本,它绘制了同一图中的一些图形.所有图形都是由draw()创建的,最后我调用show()函数来阻止.
该脚本用于Python 2.6.6,Matplotlib 0.99.3和Ubuntu 11.04.试图在Python 2.7.2,Matplotlib 1.0.1和Ubuntu 11.10下运行它,但show()函数立即返回而不等待杀死数字.
这是一个错误吗?或者一个新功能,我们将不得不改变我们的脚本?有任何想法吗?
编辑:它确实在交互模式下保持打开情节,即python -i ...,但它曾经没有这个工作,并试图在脚本中运行plt.ion()并在正常模式下运行但没有运气.
我正在尝试创建一个文件选择器对话框.但是,当我尝试tkMessageBox在Python 3中导入时,我收到一个错误,声称该模块不存在.
import tkMessageBox
# ImportError: No module named 'tkMessageBox'
Run Code Online (Sandbox Code Playgroud)
尝试在Python 3中导入其他Tkinter模块时,我遇到类似的错误.
import Tkinter # No module named 'Tkinter'
import tkColorChooser # No module named 'tkColorChooser'
import tkFileDialog # No module named 'tkFileDialog'
Run Code Online (Sandbox Code Playgroud)
如何在Python 3中导入Tkinter模块?什么是新模块名称?
I am trying to plot a simple graph using pyplot, e.g.:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[5,7,4])
plt.show()
Run Code Online (Sandbox Code Playgroud)
but the figure does not appear and I get the following message:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
Run Code Online (Sandbox Code Playgroud)
I saw in several places that one had to change the configuration of matplotlib using the following:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
Run Code Online (Sandbox Code Playgroud)
I did this, but then got an error message because it …
当我回答Tkinter问题时,我通常会尝试自己运行代码,但有时我会收到此错误:
Traceback (most recent call last):
File "C:\Python27\pygame2.py", line 1, in <module>
from tkinter import *
ImportError: No module named tkinter
Run Code Online (Sandbox Code Playgroud)
当我看到问题时,我看到他们tkinter用小写t 导入:
from tkinter import *
Run Code Online (Sandbox Code Playgroud)
我总是Tkinter用大写字母T 进口:
from Tkinter import *
Run Code Online (Sandbox Code Playgroud)
这总是适合我.使用tkinter和有Tkinter什么区别?
我正在尝试使用带有标准库Tkinter的Python 3.2测试GUI代码,但我无法导入库.
这是我的测试代码:
from Tkinter import *
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
shell报告此错误:
Traceback (most recent call last):
File "<pyshell#9>", line 1, 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 2.7将Tkinter导入我的项目,而是我收到错误:
ImportError:没有名为tkinter的模块
在任何人说出来之前,我已经尝试了"Tkinter"和"tkinter",但却得到了完全相同的信息.
好的,我遇到了一个奇怪的问题。据我了解,Tkinter 应该内置于 python 2 和 3 中。
我可以在 python3 和 IDLE3 下的终端中很好地导入和使用 Tkinter。但是,当我尝试在 Visual Studio Code 中导入 Tkinter 时,出现“ImportError: No module named 'tkinter'。
同样的问题也发生在 Pycharm 中,但我的解释器设置为与我的终端相同,而不是特定于项目的解释器。
我尝试了以下方法:
import tkinter
from tkinter import *
try:
import tkinter
except ImportError:
import Tkinter as tkinter #Even though I'm using python3
Run Code Online (Sandbox Code Playgroud)
这些都不起作用,知道为什么吗?我也在使用 Linux Mint。
我正在尝试在我的 Ubuntu (18.04) Windows 子系统上使用 tkinter 运行一个简单的 python 脚本 (3.6.8)。
import tkinter
root = tkinter.Tk()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
我总是收到以下错误: _tkinter.TclError:没有显示名称并且没有 $DISPLAY 环境变量
我尝试用谷歌的不同提示自行修复它,但我唯一实现的是运行这两个命令后得到一个新的错误代码:
导出显示=0.0
主机+
新错误代码:_tkinter.TclError:无法连接以显示“0.0”
如何在 Ubuntu 上运行 tkinter?
预先非常感谢您的帮助!
python tkinter python-3.x windows-subsystem-for-linux ubuntu-18.04
这是我在 StackOverflow 上的第一篇文章,如果您有任何改进我的文章的建议,我会尽量使其正确和完整,我很乐意接受。
我在运行使用 Tkinter 的 Python 编写的代码时遇到问题。
我将尝试详细描述我的操作,以方便识别错误。
我在 Coursera 上开设了一门关于 DSP(数字信号处理)的课程,建议安装一个用 python(和一点 C 语言)编写的工具。我正在使用 Arch Linux。
Github 上的链接: sms-tools repo
使用pyenv/virtualenv/virtualenvwrapper我创建了一个使用 Python 3.7.5 的环境,如存储库的“如何使用”部分中所推荐。
我通过 pip 在我的环境中安装了所需的库:
%pip install ipython numpy matplotlib scipy cython
我在“/sms-tools/software/models/utilFunctions_C”中编译了一些C函数
使用以下命令的目录:
%python compileModule.py build_ext --inplace
最后,我在目录“/sms-tools/software/models_interface”中运行模型GUI
%python models_GUI.py
我收到以下消息:
Traceback (most recent call last):
File "models_GUI.py", line 6, in <module>
from Tkinter import * ## notice capitalized T in Tkinter
ModuleNotFoundError: No module named 'Tkinter'
During handling …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Python 3.10 项目中使用 Tkinter。我已经使用 Python 3.10 创建了虚拟环境并安装了 Tkinter。当我运行时,import tkinter出现以下错误。
Traceback (most recent call last):
File "/home/xxx/yyy/main.py", line 11, in <module>
import tkinter
File "/usr/local/lib/python3.10/tkinter/__init__.py", line 37, 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)
但是,如果我在使用 Python 3.9 的虚拟环境之外执行相同的操作,或者使用 Python 3.9 创建一个新的虚拟环境,则它可以正常运行,不会出现错误。
3.10 中是否还不支持 Tkinter,还是我可能做错了什么?
python ×11
tkinter ×10
python-3.x ×5
import ×2
linux ×2
matplotlib ×2
install ×1
installation ×1
pycharm ×1
pyenv ×1
python-3.10 ×1
python-3.9 ×1
tcl ×1
ubuntu-18.04 ×1