about Frame.__init__(self)

M.E.Farmer mefjr75 at hotmail.com
Wed Apr 27 03:26:16 EDT 2005


Hello ,
I am no expert on tkinter but this seems like an inheritance question.
When you define a class that inherits from something ( Frame ) and you
define an __init__ in your class you have to explicitly call the
__init__ of your base class.

class xxx(base):
    """ This class doesn't have an __init__ defined.
        base.__init__ is called instead
    """
    def method_a(self):
        pass

class xxx(base):
    """ This class defines an __init__ and has to
        explicitly call the base.__init__
    """
    def __init__(self):
        """Python calls me if I am defined"""
        base.__init__(self)

You will see this in more than GUI code, it is part of Python's OO
design.
I first saw this in some threading code , thru me for a loop too ;)
search strategy:
Python OO
Python inheritance
etc...
hth,
M.E.Farmer

yang wrote:
> I just a newbie of python
> Now I found that almost every program use Tkinter have this line
>
> class xxx(xxx):
>      """xxxxx"""
>
>      def __init__(self):
>          """xxxxx"""
>
>          Frame.__init__(self)
>          .....................
>          .......
>
>
> the line "Frame.__init__(self)" puzzle me.
> why use it like this?
> can some one explain it?
> regards,
> yang




More information about the Python-list mailing list