我知道你会说这是一个重复,但它确实不是。即时得到错误:_tkinter模块没有找到
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
安装了一切,但我仍然得到ER ROR。它让我疯狂,我正在努力学习如何创建一个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. **
你有蟒蛇2.7和3个标记这是什么呢? – EoinS
@EoinS我有两个。我的os在2.7上运行,但是我也可以运行python3,因为iIhave它也安装在单独的部分中。如果我想运行它作为python 2.7我只是告诉它运行它作为python文件'python calculator.py'或者如果我想运行它在python 3我告诉它'python3 calculator.py' – Matt