Re: [Tutor] Super In tkinter class inheritance
class ChooseDestinationWindow(Frame): def __init__(self,master): super(ChooseDestinationWindow,self).__init_ _(master) What exactly does this super method since I have seen it numerous times before and as far as I can see it is not anything the user created himself in the class? This has to do a lot with inheritance in object-oriented programming. If you are not aware of this, you might want to read some basics on that. The gist of the reason to call super is that the TKinter (or whatever base class) does some work in the background to create a Frame type, so if you are inheriting from the Frame class, you still (normally) want the Frame class to behave normally with very specific deviations. For instance, you may want to setup the Frame but (like an Office-type application) have it ask the user to save when the app tries to close. You use super in a function to call the behavior of the base class so that you do not need to duplicate the code. It is a fairly language-agnostic OOP idea. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Super In tkinter class inheritance
I was observing the tkinter code under the topic Creating arbitrary number of destinations. (GUI program) in the previous email and saw this super thing: class ChooseDestinationWindow(Frame): def __init__(self,master): super(ChooseDestinationWindow,self).__init_ _(master) What exactly does this super method since I have seen it numerous times before and as far as I can see it is not anything the user created himself in the class? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Super In tkinter class inheritance
On 07/12/11 17:01, George Nyoro wrote: I was observing the tkinter code under the topic Creating arbitrary number of destinations. (GUI program) in the previous email and saw this super thing: class ChooseDestinationWindow(Frame): def __init__(self,master): super(ChooseDestinationWindow,self).__init_ _(master) What exactly does this super method since I have seen it numerous times before and as far as I can see it is not anything the user created himself in the class? It's the recommended way to call the super-class version of a method. In older versions of Python it would be done like this: class C(A): def m(self): A.m(self) # call superclass method m() # local code here In later versions of Python it has been possible to use the super() style instead which works better in some cases. In Python v3 it is now the only approved way to call the superclass (although the older way still works for simple cases, but you should just get used to super()... but I'm struggling to follow my own advice! ;-). -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor