Using property() to extend Tkinter classes but Tkinter classes are old-style classes?

Michele Simionato michele.simionato at gmail.com
Mon Nov 29 05:33:19 EST 2010


On Nov 29, 12:15 am, Terry Reedy <tjre... at udel.edu> wrote:
> On 11/28/2010 3:47 PM, pyt... at bdurham.com wrote:
>
> > I had planned on subclassing Tkinter.Toplevel() using property() to wrap
> > access to properties like a window's title.
> > After much head scratching and a peek at the Tkinter.py source, I
> > realized that all Tkinter classes are old-style classes (even under
> > Python 2.7).
> > 1. Is there a technical reason why Tkinter classes are still old-style
> > classes?
>
> To not break old code. Being able to break code by upgrading all classes
> in the stdlib was one of the reasons for 3.x.
>
> --
> Terry Jan Reedy

Notice that you can upgrade a Tkinter class to a new-style class
simply by deriving from object.
For instance you could define a new-style Label class as:

class Label(Tkinter.Label, object):
   pass


then you can attach properties to it. You have a good chance of not
breaking anything in doing so,
but you cannot know for sure unless you try. I don't know if Tkinter
uses features of old-style classes which are inconsistent with new-
style classes, but probably the answer is not much.

 Michele Simionato



More information about the Python-list mailing list