[Tutor] What does parent=0 mean?
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Tue Aug 24 21:26:28 CEST 2004
On Tue, 24 Aug 2004, Klas Marteleur wrote:
> I am going thru theGUI programing chapter in Alans latest web tutorial. And
> found this example:
> -----------------------------------------
> from Tkinter import *
>
> class ClearApp:
> def __init__(self, parent=0):
> self.mainWindow = Frame(parent)
> # Create the entry widget
[code cut]
> What does parent=0 mean?
Hi Klas,
This is an example of a default parameter. Python allows us to declare
default values for the parameters of a function. For example:
###
>>> def sayHello(name="Klas"):
... print "hello", name
...
>>> sayHello()
hello Klas
>>> sayHello('dyoo')
hello dyoo
###
So if we don't pass a parameter off, Python uses the default value. The
Python Tutorial talks about this in section 4.7.1. "Default Argument
Values":
http://www.python.org/doc/tut/node6.html#SECTION006710000000000000000
Hope this helps!
More information about the Tutor
mailing list