IDLE 2.7.11/12 “NameError: global name 'Toplevel' is not defined" [英] IDLE 2.7.11/12 "NameError: global name 'Toplevel' is not defined"

查看:152
本文介绍了IDLE 2.7.11/12 “NameError: global name 'Toplevel' is not defined"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Oracle VB 上的基于 Debian 的操作系统上运行 APT-GET 更新.在它运行时,我在 IDLE 2.7.12 中处理了一些 python 代码(我用终端打开了它).更新完成后,我尝试保存我的代码.在我打开 IDLE 的终端中,出现错误.它是这样说的:

I ran APT-GET update on a Debian based OS on Oracle VB. While it was running I messed around with some python code in IDLE 2.7.12 (I opened it with a terminal). After it finished updating, I tried saving my code. In the terminal that I opened IDLE with I got an error. It says this:

root@kali:~# idle

root@kali:~# idle

空闲打开,我加载我的代码,我编辑我的代码,然后我点击[文件][保存]

Idle opens, I load my code, I edit my code, then I click [FILE] [SAVE]

发生这种情况

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1545, in __call__
    return self.func(*args)
  File "/usr/lib/python2.7/idlelib/ScriptBinding.py", line 140, in run_module_event
    filename = self.getfilename()
  File "/usr/lib/python2.7/idlelib/ScriptBinding.py", line 205, in getfilename
    self.editwin.io.save(None)
  File "/usr/lib/python2.7/idlelib/IOBinding.py", line 345, in save
    if self.writefile(self.filename):
  File "/usr/lib/python2.7/idlelib/IOBinding.py", line 378, in writefile
    chars = self.encode(self.text.get("1.0", "end-1c"))
  File "/usr/lib/python2.7/idlelib/IOBinding.py", line 450, in encode
    dialog = EncodingMessage(self.editwin.top, enc)
  File "/usr/lib/python2.7/idlelib/IOBinding.py", line 76, in __init__
    self.root = top = Toplevel(master)
NameError: global name 'Toplevel' is not defined

我的终端出现错误的图片

我已经尝试过重新启动 VB,但我已经卸载、自动清理,然后重新安装了 IDLE,但没有成功.

I have already tried restarting the VB, and I've uninstalled, autocleaned, then re-installed IDLE with no luck.

推荐答案

问题是 IDLE 更新版本中的一个错误.在.../Lib/idlelib/IOBinding.py的顶部附近添加以下内容,例如在import tkFileDialog之前.

The problem is a bug in the updated version of IDLE. Add the following near the top of .../Lib/idlelib/IOBinding.py, for instance before import tkFileDialog.

from Tkinter import *

NameError 发生在一个函数中,该函数显示带有以下消息的警告:

The NameError occured in a function that displays a warning with the following message:

Non-ASCII found, yet no encoding declared. Add a line like
-*- coding: <enc> -*-
Choose OK to save this file as <enc>
Edit your general options to silence this warning

其中 将是一种编码,例如 utf-8.

where <enc> will be an encoding such as utf-8.

我觉得如果该消息指向 Python 语言参考,第 2.1.4 节,编码声明,可能对初学者更有帮助

It occurs to me that the message might be more helpful for beginners if it pointed to the Python Language Reference, Section 2.1.4., Encoding declarations

这个错误是 2.x 特有的,因为在 Python3 中,utf-8 是在没有编码声明的情况下默认使用的.

This bug is 2.x specific because in Python3, utf-8 is the default used in the absence of an encoding declaration.

这篇关于IDLE 2.7.11/12 “NameError: global name 'Toplevel' is not defined"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆