【问题标题】:Python easygui , global name 'Tk' is not definedPython easygui,未定义全局名称“Tk”
【发布时间】:2015-10-08 21:46:54
【问题描述】:

我正在尝试执行以下代码sn-p:

import easygui
from Tkinter import *
easygui.msgbox('Hello')

但它返回以下错误:

NameError                                 Traceback (most recent call last)
<ipython-input-35-28d6ffa54e48> in <module>()
----> 1 easygui.msgbox('Hello')

/usr/local/lib/python2.7/dist-packages/easygui/boxes/derived_boxes.pyc in msgbox(msg, title, ok_button, image, root)
    214                         root=root,
    215                         default_choice=ok_button,
--> 216                         cancel_choice=ok_button)
    217 
    218 

/usr/local/lib/python2.7/dist-packages/easygui/boxes/base_boxes.pyc in buttonbox(msg, title, choices, image, root, default_choice, cancel_choice)
     64         boxRoot.withdraw()
     65     else:
---> 66         boxRoot = Tk()
     67         boxRoot.withdraw()
     68 

NameError: global name 'Tk' is not defined 

我尝试使用各种导入 Tkinter 组合进行故障排除 -

import Tkinter as Tk  
import Tkinter
from Tkinter import *

但它们都不起作用。我安装了这两个软件包的最新版本。怎么了?

【问题讨论】:

    标签: python-2.7 tkinter easygui


    【解决方案1】:

    也许this 有帮助。

    在您的脚本所在的目录中拥有一个名为“Tkinter”的文件会导致导入此文件而不是 Tkinter 本身

    【讨论】:

      【解决方案2】:

      如果您使用的是 3+ Python,那么它的“tkinter”而不是“Tkinter”

      如果那不是问题,那么检查你的 tkinter 路径应该是

      "\python??\lib\tkinter"

      ??作为您拥有的版本,tkinter 将是许多 py 文件的文件夹。

      Python 区分大小写。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-03
        • 2013-08-23
        • 2013-11-12
        • 2014-12-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-26
        相关资源
        最近更新 更多