On 5 Apr, 17:09, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >> def __init__(self): > >> # ... > >> button = Button(self, > >> text='1', > >> command=lambda n=1: self.display(n)) > >> # ... > > >> def display(self, number): > >> print number > > > should this really be inside the __init__ function? > > what's wrong with creating widgets in an __init__ method? > > </F>
i dont know, i used a piece of code i found which had a createwidgets- method. isnt init a function, not a method btw(or it is the same thing?) this is the current code, only included 2 buttons here to make it shorter. i might still have misinterpreted though, is the code correct(it runs correct at least...)? whats the advantage/disadvante to have it inside the init? #! /usr/bin/env python from Tkinter import * import tkMessageBox class GUIFramework(Frame): """This is the GUI""" def __init__(self, master=None): """Initialize yourself""" """Initialise the base class""" Frame.__init__(self,master) """Set the Window Title""" self.master.title("Calculator") """Display the main window" with a little bit of padding""" self.grid(padx=10,pady=10) self.CreateWidgets() def CreateWidgets(self): self.btnDisplay = Button(self,text='1',command=lambda n=1:self.Display(n)) self.btnDisplay.grid(row=3, column=0, padx=5, pady=5) self.btnDisplay = Button(self,text='/',command=lambda n="/":self.Display(n)) self.btnDisplay.grid(row=6, column=3, padx=5, pady=5) def Display(self, number): print number if __name__ == "__main__": guiFrame = GUIFramework() guiFrame.mainloop() -- http://mail.python.org/mailman/listinfo/python-list