gpt4 book ai didi

python - 这里有什么问题? (属性错误 __len__)

转载 作者:太空宇宙 更新时间:2023-11-03 10:59:47 24 4
gpt4 key购买 nike

给定这个相对简单的 tk 脚本:

import Tkinter

class buttton(Tkinter.Button):
def __init__(self,frame,action=None):
if action==None:
action=self.action
Tkinter.Button.__init__(self,frame,command=action)
self.pack(frame)
def action(self):
None


root=Tkinter.Tk()
button=buttton(root)
root.mainloop()

运行这个程序时,我遇到了一个相当神秘的错误:

Traceback (most recent call last):
File "C:/Users/username/Desktop/ab.py", line 14, in <module>
button=buttton(root)
File "C:/Users/username/Desktop/ab.py", line 8, in __init__
self.pack(frame)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1940, in pack_configure
+ self._options(cnf, kw))
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1162, in _options
cnf = _cnfmerge(cnf)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 114, in _cnfmerge
for c in _flatten(cnfs):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1898, in __getattr__
return getattr(self.tk, attr)
AttributeError: __len__

如果有任何帮助,我将非常乐意!

最佳答案

这是你的问题:

self.pack(frame)

self.pack 不接受框架参数。删除 frame,它应该可以正常运行,如下所示:

self.pack()

关于python - 这里有什么问题? (属性错误 __len__),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35209080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com