python - Call the Button contrustor from inside a class' __init__ -


my gui program uses number of buttons have couple specific features, i'm writing class wraps these methods around button don't need keep rewriting simple functions each button. have class:

class toggleablebutton(button):          __istoggled = false     __root = none     __bindmap = []      # how correctly structure init ?     def __init__(self, master=none, cnf={}, **kw):         button.__init__(self, master, cnf, kw)      def bind(self, root, bindkey, func):         # doing stuff      def toggle(self, toggle=false):         # doing stuff 

and want able create object i'd create button:

drawbutton = toggleablebutton(frame, image=img, width=30, command=func) drawbutton = toggleablebutton(frame, image=anotherimg) 

how can declare class __init__ method mimic of button? if write test = toggleablebutton(frame, text="hi", width=10, command=func) i'll error:

tools.py, line 59, in __init__     button.__init__(self, master, cnf, kw) typeerror: __init__() takes @ 3 arguments (4 given) 

you need apply (splat) keyword arguments:

button.__init__(self, master, cnf, **kw)                                    ^^ 

otherwise, passing whole kw dict single positional argument. raises error since button.__init__ accepts 3 positional arguments (self, master, , cnf), not four.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -