about Frame.__init__(self)

Y

yang

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
 
M

M.E.Farmer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,236
Messages
2,571,184
Members
47,820
Latest member
HortenseKo

Latest Threads

Top