[Tutor] What does parent=0 mean?

Chad Crabtree flaxeater at yahoo.com
Tue Aug 24 22:16:09 CEST 2004


Klas Marteleur wrote:

>-----------------------------------------
>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()
>--------------------------------------------
>

Just to clarify a little on what the others said.  The above line
could
say def __init__(self, parent=None):
I believe that the only tkinter widget that can have no parent is the
frame.    When a frame has no parent then it is the main frame that
hold
*everything* else.    What this allows is for this to be used as
though
it was it's own widget (a compound widget) and put inside another
app.
However if you never ever intended it to be used that way you could
use
"self.mainWindow=Frame(None)" and use no default argument on the init
function.

I hope this is helpful to you and not to confusing,  I found Gui
programing to be very hard at first.



	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 


More information about the Tutor mailing list