2016-05-23 94 views
2

我知道你会说这是一个重复,但它确实不是。即时得到错误:_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. **

+0

你有蟒蛇2.7和3个标记这是什么呢? – EoinS

+0

@EoinS我有两个。我的os在2.7上运行,但是我也可以运行python3,因为iIhave它也安装在单独的部分中。如果我想运行它作为python 2.7我只是告诉它运行它作为python文件'python calculator.py'或者如果我想运行它在python 3我告诉它'python3 calculator.py' – Matt

回答

2

这部分回溯表明tkinter i S是从/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 

加载即的Tkinter已经手动安装(不通过的软件包管理器),以/usr/local/lib/python3.4

但是,这意味着你已经安装了Python和Tkinter的使用包管理器。

Updated my OS to the latest system installed tkinter installed python-tk installed python3-tk

我想你可能需要删除安装Tkinter的/usr/local/lib/python3.4/tkinter如果你有Tkinter的也作为一个软件包安装(Ubuntu的软件包?),或重命名的目录并做一些测试。

+0

好吧,生病第一次删除安装到python3.4的目录 – Matt

+0

现在工作...以及没有工作,但不再给我“无模块”的错误 – Matt

2

的Python 2.7的标记,您使用的Python的版本。

在Python 2.7中,模块是Tkinter,它只在Python 3中更改为tkinter。模块名称区分大小写。

尝试

From Tkinter import * 

如果您使用的是Mac OS有可能是several issues使用TK

这里有个安装文档,非常有帮助:tk docs

从你应该在终端窗口那么可以运行一个Python shell: %/usr/local/bin/python3.4 这应该会给你一个Python命令提示符。从提示符下,输入以下两条命令:

import tkinter 
tkinter._test() 

这应该弹出一个小窗口;在窗口顶部的第一行应该说

"This is Tcl/Tk version 8.5"; make sure it is not 8.4! 

您还可以得到的正在使用的Tcl/Tk的准确版本:

tkinter.Tcl().eval('info patchlevel') 

应该返回的东西像

'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. 
+0

这是正确的 –

+0

我有2.7和3.4。我的os在2.7上运行,但是我也可以运行python3,因为iIhave它也安装在单独的部分中。如果我想运行它作为python 2.7我只是告诉它运行它作为python文件python calculator.py或者如果我想运行它在python 3我告诉它python3 calculator.py – Matt

+0

此外,我已经尝试过tkinter和Tkinter的。我得到的错误,无论我在2.7或3上运行它。我的操作系统是薄荷 – Matt

1

也许为时已晚,但是......)

1)5号线:在 '高清按钮' BD'而不是 '数据库'

2)你没有返回storeObj

3 )''class app'all loop'for'should'in'init'。缩进

4)你的应用程序没有必须属性“钙”

def calc(self, display): 
    try: 
     display.set(eval(display.get())) 
    except: 
     display.set('ERROR')