[英]What is wrong here? (Attribute Error __len__)
Given this relatively simple tk script: 鉴于这个相对简单的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()
When running this program, I am met with the rather cryptic error: 运行这个程序时,我遇到了相当神秘的错误:
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__
I would be more than happy for any help! 如果有任何帮助,我会非常高兴!
Here is your problem: 这是你的问题:
self.pack(frame)
self.pack
doesn't take a frame argument. self.pack
不接受frame参数。 Remove frame
, and it should run fine, like so: 删除
frame
,它应该运行正常,如下所示:
self.pack()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.