[Tutor] Super In tkinter class inheritance

Alan Gauld alan.gauld at btinternet.com
Wed Dec 7 23:45:39 CET 2011


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/



More information about the Tutor mailing list