Python __init__() how don't override important functionality?
<p>I need to add another option in a class, a simple 'edit=False'. Whithout override completely <strong>init</strong>().
I found this piece of code written for kivy:</p>

<pre><code>class TitleBox(BoxLayout):
    def __init__(self, **kwargs):
        # make sure we aren't overriding any important functionality
        super(TitleBox, self).__init__(**kwargs)
</code></pre>

<p>But when I try to edit for my purposes I receive: "TypeError: <strong>init</strong>() takes at most 2 arguments (3 given)"</p>

<pre><code>class Person_Dialog(tkSimpleDialog.Dialog):
    def __init__(self, edit=False, **kwargs):
        super(Person_Dialog, self).__init__(**kwargs)
        self.edit = edit
</code></pre>

<p>Given an <code>__init__</code> signature of:</p>

<pre><code>def __init__(self, edit=False, **kwargs):
</code></pre>

<p>When you do this:</p>

<pre><code>add = Person_Dialog(root, 'Add person')
</code></pre>

<p>Python creates an instance and assigns it to the <code>self</code> argument.  Then it assigns <code>root</code> to the <code>edit</code> argument.  Then it takes <code>'Add a person'</code> and finds no other <em>positional</em> arguments to assign it to.</p>

<p>To fix this add another argument to <code>__init__</code>:</p>

<pre><code>class Person_Dialog(tkSimpleDialog.Dialog):
    def __init__(self, parent, edit=False, **kwargs): # added parent argument
        super(Person_Dialog, self).__init__(parent, **kwargs)
        self.edit = edit
</code></pre>

<p>Note that we also pass <code>parent</code> to the superclass because <code>tkSimpleDialog.Dialog</code> has this signature <code>__init__(self, parent, title=None)</code>.</p>

<p>Unfortunately, your code now fails with <code>TypeError: must be type, not classobj</code> because <code>tkSimpleDialog.Dialog</code> is an old style class and you can't use <code>super()</code> with old style classes.  (Python 3 does away with old style classes, so you won't have this issue there.)</p>

<p>So to fix this replace the call to <code>super()</code> with a direct reference to the superclass:</p>

<pre><code>class Person_Dialog(tkSimpleDialog.Dialog):
    def __init__(self, parent, edit=False, **kwargs):
        # referencing the superclass directly
        tkSimpleDialog.Dialog.__init__(self, parent, **kwargs) 
        self.edit = edit
</code></pre>

<p>Now your code will work.</p>

python tkinter init super