[Tutor] Class Inheritance, Beat it into the Ground
steve at pearwood.info
Sat Apr 24 08:18:55 CEST 2010
On Sat, 24 Apr 2010 03:41:04 pm David Hutto wrote:
> In previous post I asked about turtle module importing from tkinter.
> But what I don't understand is why does Tkinter default it's casnvas
> to ScrolledCanvas in turtle.py, and then as a 'metaclass' for
> ScrolledCanvas in turtle it calls TK.Frame, which could have
> been set as a default within Tkinter itself?
Tkinter doesn't know anything about turtle. turtle is an independent
module which is built on top of Tkinter.
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
AttributeError: 'module' object has no attribute 'turtle'
Yes, Tkinter could have had a ScrolledCanvas. It could have had lots of
things, you have to draw the line somewhere otherwise you end up with
one giant module that does *everything*:
>>> import UniversalModuleWithEverything # takes a few hours to load
>>> UniversalModuleWithEverything. \
Tkinter doesn't do anything in turtle. turtle wants a ScrolledCanvas,
and since Tkinter doesn't have one, it creates it. It uses Tkinter's
Frame object as the base class (not a metaclass, metaclasses are an
advanced technique which are very different). That way the
ScrolledCanvas class inherits behaviour from Frame.
More information about the Tutor