IDLE 2.7.11/12 “NameError: global name 'Toplevel' is not defined”

后端 未结 2 519
梦如初夏
梦如初夏 2021-01-26 08:56

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 finishe

相关标签:
2条回答
  • 2021-01-26 08:58

    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 *
    

    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
    

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

    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

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

    0 讨论(0)
  • 2021-01-26 09:07

    open IDLE.
    Options
    Configure IDLE
    General
    set 'Default Source Encoding' : UTF-8

    I'm running Python 2.7.12 on Windows 10 and also Ubuntu 16.04 this solved my save/crash IDLE issue on both OS's .

    Why do I get the feeling they are trying to throw us off Python 2 to 3 ?! jk.

    0 讨论(0)
提交回复
热议问题