[Tutor] What does parent=0 mean?
Kent Johnson
kent_johnson at skillsoft.com
Tue Aug 24 21:16:48 CEST 2004
A function or method definition can have optional arguments. These are
function arguments that may be omitted by the caller. If they are omitted,
they take on a default value given in the function definition. So
def __init__(self, parent=0):
defines a function called __init__ that has one required argument (self)
and one optional argument (parent) whose default value is 0.
In this particular case, the default argument of 0 is interpreted to mean,
"use the root window".
This page in the Python tutorial has more information about default
arguments: http://docs.python.org/tut/node6.html#SECTION006710000000000000000
Kent
At 08:24 PM 8/24/2004 +0200, Klas Marteleur wrote:
>Hi
>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
> self.entry = Entry(self.mainWindow)
> self.entry.insert(0,"Hello world")
> self.entry.pack(fill=X)
>
> # now add the 2 buttons, use a grooved effect
> fButtons = Frame(fOuter, border=2, relief="groove")
> bClear = Button(fButtons, text="Clear",
> width=8, height=1, command=self.clearText)
> bQuit = Button(fButtons, text="Quit",
> width=8, height=1, command=self.mainWindow.quit)
> bClear.pack(side="left", padx=15, pady=1)
> bQuit.pack(side="right", padx=15, pady=1)
> fButtons.pack(fill=X)
> self.mainWindow.pack()
>
> # set the title
> self.mainWindow.master.title("Clear")
>
> def clearText(self):
> self.entry.delete(0,END)
>
>app = ClearApp()
>app.mainWindow.mainloop()
>--------------------------------------------
>
>What does parent=0 mean?
>
>Klas
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list