2
我的程序如下:为什么我的框架子类在init中抛出一个错误?
from Tkinter import *
class TFrame(Frame):
def __init__(self, master=None, cnf={}, **kw):
Frame.__init__(self, master, cnf, kw)
if __name__ == '__main__':
root = Tk()
tf = TFrame(root)
tf.pack()
root.mainloop()
,我得到这个错误:
Traceback (most recent call last):
File "testFrame.py", line 11, in <module>
tf = TFrame(root)
File "testFrame.py", line 7, in __init__
Frame.__init__(self, master, cnf, kw)
TypeError: __init__() takes at most 3 arguments (4 given)
怎么会我得到这里TypeError
?我做类似的事情,如Tkinter.Label
类。
的框架类的代码是在这里:
`class Frame(Widget):
"""Frame widget which may contain other widgets and can have a 3D border."""
def __init__(self, master=None, cnf={}, **kw):
"""Construct a frame widget with the parent MASTER.
Valid resource names: background, bd, bg, borderwidth, class,
colormap, container, cursor, height, highlightbackground,
highlightcolor, highlightthickness, relief, takefocus, visual, width."""
cnf = _cnfmerge((cnf, kw))
extra =()
if 'class_' in cnf:
extra = ('-class', cnf['class_'])
del cnf['class_']
elif 'class' in cnf:
extra = ('-class', cnf['class'])
del cnf['class']
Widget.__init__(self, master, 'frame', cnf, {}, extra)`