我知道你會說這是一個重複,但它確實不是。即時得到錯誤:_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