【发布时间】:2017-03-21 20:26:32
【问题描述】:
我知道你会说这是重复的,但事实并非如此。我得到了错误:
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. **
【问题讨论】:
-
你有 python 2.7 和 3 标记它是什么?
-
@EoinS 我两者都有。我的操作系统在 2.7 上运行,但我也可以运行 python3,因为我也将它安装在单独的部分中。如果我想将它作为 python 2.7 运行,我只是告诉它作为 python 文件运行
python calculator.py或者如果我想在 python 3 中运行它,我告诉它python3 calculator.py
标签: python python-3.x tkinter