我知道你会说这是重复的,但事实并非如此。我收到错误:
Traceback (most recent call last):
File "calculator.py", line 1, in <module>
from tkinter import *
File "/usr/local/lib/python3.4/tkinter/__init__.py", line 38, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'
我已经检查了每个站点上提供的所有错误和解决方案,包括我拥有的这个
将我的操作系统更新到最新系统
安装的 tkinter
安装 python-tk
安装python3-tk
安装了 tk-dev
安装的 tcl
安装了所有东西,但我仍然收到错误。这让我发疯,我正在努力学习如何制作 GUI,以便我的脚本对那些无法理解命令行脚本的人更有帮助。但是,如果我的练习脚本都不起作用,那么我将无能为力。如果您想查看,这是我正在运行的脚本。没什么特别的。
from tkinter import *
def iCalc(source, side):
storeObj = Frame(source, borderwidth=4, db=4, bg="red")
storeObj.pack(side=side, expand=YES, fill=BOTH)
return storeObj
def button(source, side, text, command=None):
storeObj = Button(source, text=text, command=command)
storeObj.pack(side=side, expand=YES, fill=BOTH)
class app(Frame):
def __init__(self):
Frame.__init__(self)
self.option_add('*Font', 'arial 20 bold')
self.pack(expand=YES, fill=BOTH)
self.master.title('Calculatorinator')
display = StringVar()
Entry(self, relief=RIDGE,
textvariable=display, justify='right', bd=30, bg="red").pack(side=TOP, expand=YES,
fill=BOTH)
for clearBut in (["CE"], ["C"]):
erase=iCalc(self, TOP)
for ichar in clearBut:
button(erase, LEFT,ichar,
lambda storeObj=display, q=ichar:storeObj.set(''))
for NumBut in ("789/", "456*", "123-", "0.+"):
FunctionNum = iCalc(self, TOP)
for char in NumBut:
button(FunctionNum, LEFT, char,
lambda storeObj=display, q=char: storeObj.set(storeObj.get() + q))
EqualsButton = iCalc(self, TOP)
for iEquals in "=":
if iEquals == '=':
btniEquals = button(EqualsButton, LEFT, iEquals)
btniEquals.bind('<ButtonRelease-1>',
lambda e, s=self, storeObj=display: s.calc(storeObj), '+')
else:
btniEquals = button(EqualsButton, LEFT, iEquals,
lambda storeObj=display, s=' %s '%iEquals: storeObj.set(storeObj.get()+s))
if __name__ == '__main__':
app().mainloop()
更新:现在它甚至不会让我闲置: idle3.4
** IDLE can't import Tkinter.
Your Python may not be configured for Tk. **
原文由 Matt 发布,翻译遵循 CC BY-SA 4.0 许可协议
这部分回溯表明正在从 /usr/local/lib/python3.4 加载 tkinter
即 tkinter 已手动安装(不是通过包管理器)到 /usr/local/lib/python3.4
但这表明您已经使用包管理器安装了 python 和 tkinter。
我想你可能必须删除安装到 /usr/local/lib/python3.4/tkinter 的 tkinter 如果你也安装了 tkinter 作为一个包(ubuntu 包?),或者重命名目录并做一些测试。