[Tutor] OOP clarification needed
Jim Byrnes
jf_byrnes at comcast.net
Wed Jun 2 17:46:12 CEST 2010
Steven D'Aprano wrote:
>>
>> Case in point is this code snippet from a chapter on Tkinter.
>>
>> def viewer(imgdir, kind=Toplevel, cols=None):
>> """
>> make thumb links window for an image directory:
>> one thumb button per image; use kind=Tk to show
>> in main app window, or Frame container (pack);
>> imgfile differs per loop: must save with a default;
>> photoimage objs must be saved: erased if reclaimed;
>> """
>> win = kind()
>> win.title('Viewer: ' + imgdir)
>> thumbs = makeThumbs(imgdir)
>> <snip>
>>
>
> In the example you give, you have an argument named "kind". It is
> expected to be some sort of function or class, and gets the default
> value of TopLevel if not supplied. In the body of the function, this
> function or class is called, to produce a value which is then
> named "win". Judging by the default value and the name of the inner
> variable, I would say it is expected to produce a window object, so any
> function or class that returns a window object will be suitable.
>
I completely overlooked this expectation, which led to my confusion.
Thanks for the explanation.
Regards, Jim
More information about the Tutor
mailing list