首页 > 解决方案 > “AttributeError: '_tkinter.tkapp' 对象没有属性 '__name__'” 在使用 '.after_idle' 时

问题描述

.after_idle用来确保我的 tkinter 程序在循环中不会崩溃。

但是每次我按下start(tkinter.Button()) 按钮时,都会发生这种情况:

Exception in Tkinter callback
Traceback (most recent call last):
  File ************************************************************, line 1883, in __call__
    return self.func(*args)
  File ************************************************************, line 78, in panel
    win.after_idle(win, panel)
  File ************************************************************, line 820, in after_idle
    return self.after('idle', func, *args)
  File ************************************************************, line 810, in after
    callit.__name__ = func.__name__
  File ************************************************************, line 2345, in __getattr__
    return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute '__name__'

我怎样才能解决这个问题?是什么原因造成的?帮助回答:

这是我的代码:

import tkinter
import os
import time
#control rod percentages
cr1 = 100

p = '%'

#grid pieces
c1 = 'CTRL ROD 01 '
ins = ' INSERTED'

grid1 = ' _________________________ '
grid2 = '|'
grid3 = '|_________________________|'
def panel():
    print(grid1)
    print(grid3)
    win.after_idle(panel)
    os.system('cls')

win = tkinter.Tk(className=' N.M.S. ')
w = tkinter.Button(win, activeforeground="black", activebackground="red", bg="grey", fg="black", command=panel, text="START", height=1, width=10)
w.pack()
win.mainloop()

-------------------------------------------------- - -[笔记] - - - - - - - - - - - - - - - - - - - - - - ----------------------

此代码不完整。它处于建设和测试阶段。我刚刚遇到了这个问题,我真的被它难住了。

PS:我使用的是 python 3.8.0。这有什么改变吗?

标签: python-3.xtkinterattributeerror

解决方案


推荐阅读