Importing from a Package in IDLE vs Shell

后端 未结 1 1750
陌清茗
陌清茗 2020-12-12 04:50

Importing a whole package works in IDLE, but not in shell. The following works fine in IDLE:

import tkinter as tk
tk.filedialog.askopenfilename()


        
相关标签:
1条回答
  • 2020-12-12 05:40

    This is an IDLE bug which I fixed for future 3.5.3 and 3.6.0a4 releases. Tracker issue.

    For an existing 3.5 or 3.4 release, add the following to idlelib/run.py just before the LOCALHOST line.

    for mod in ('simpledialog', 'messagebox', 'font',
                'dialog', 'filedialog', 'commondialog',
                'colorchooser'):
        delattr(tkinter, mod)
        del sys.modules['tkinter.' + mod]
    

    I presume that this will work with earlier 3.x releases, but do not have them installed to test. For existing 3.6.0a_ releases, replace 'colorchooser' with 'ttk'.

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