Reputation: 105
I know you are going to say this is a duplicate but it really isn't. Im getting the error:
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'
I have gone through ALL errors and solutions given on EVERY site including this one I have
Updated my OS to the latest system
installed tkinter
installed python-tk
installed python3-tk
installed tk-dev
installed tcl
installed EVERYTHING and yet i still get the error. it's driving me nuts,I'm trying to learn how to make a GUI so my scripts can be more helpful to the people who cant figure out command line scripts. But if none of my practice scripts work then I cant do anything. this is the script I'm running if you want to see it. nothing special.
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()
UPDATE: Now it wont even let me run idle: idle3.4
** IDLE can't import Tkinter.
Your Python may not be configured for Tk. **
Upvotes: 3
Views: 15405
Reputation: 13
Maybe its too late, but...)
1) line 5: 'bd' not 'db'
2) in 'def button' you didnt return storeObj
3) in 'class app' all loop 'for' should be in 'init'. Indent
4) You app didnt have attribute 'calc'
def calc(self, display):
try:
display.set(eval(display.get()))
except:
display.set('ERROR')
Upvotes: 1
Reputation: 6214
This part of the backtrace indicates that tkinter is being loaded from /usr/local/lib/python3.4
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
i.e. tkinter has been manually installed (not through a package manager) to /usr/local/lib/python3.4
But this suggests you have installed python and tkinter using package manager.
Updated my OS to the latest system installed tkinter installed python-tk installed python3-tk
I think you may have to remove tkinter installed to /usr/local/lib/python3.4/tkinter if you have tkinter also installed as a package (ubuntu package?), or rename the directory and do some testing.
Upvotes: 2
Reputation: 5482
Python 2.7 is tagged, which version of Python are you using.
In Python 2.7 the module is Tkinter which changes to tkinter only in Python 3. Modules names are case sensitive.
Try
From Tkinter import *
If you are using Mac OS there could be several issues using tk
Here are the th install docs, very helpful: tk docs
From a Terminal window you should then be able to run a Python shell: % /usr/local/bin/python3.4 This should give you the Python command prompt. From the prompt, enter these two commands:
import tkinter
tkinter._test()
This should pop up a small window; the first line at the top of the window should say
"This is Tcl/Tk version 8.5"; make sure it is not 8.4!
You can also get the exact version of Tcl/Tk that is being used with:
tkinter.Tcl().eval('info patchlevel')
which should return something like
'8.5.18'.
Verified install using ActiveTcl 8.5.18.0 and Python 3.4.3 from python.org on Mac OS X 10.10.3.
Upvotes: 2