Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Using property() to extend Tkinter classes but Tkinter classesare old-style classes?

Reply
Thread Tools

Re: Using property() to extend Tkinter classes but Tkinter classesare old-style classes?

 
 
Terry Reedy
Guest
Posts: n/a
 
      11-28-2010
On 11/28/2010 3:47 PM, http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
Michele Simionato
Guest
Posts: n/a
 
      11-29-2010
On Nov 29, 12:15*am, Terry Reedy <(E-Mail Removed)> wrote:
> On 11/28/2010 3:47 PM, (E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
python@bdurham.com
Guest
Posts: n/a
 
      11-29-2010
Michele and Terry,

> From: "Michele Simionato" <(E-Mail Removed)>
>
> 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


Michele - your technique is *exactly* what I was searching for (and
works well so far!). Terry - your explanation why Tkinter still uses old
style classes (for compatibility with existing code) makes sense.

Thank you both.

Malcolm
 
Reply With Quote
 
Giacomo Boffi
Guest
Posts: n/a
 
      11-30-2010
Terry Reedy <(E-Mail Removed)> writes:

> On 11/28/2010 3:47 PM, (E-Mail Removed) 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.


In 3.x, are Tkinter classes still derived by old-style classes?
 
Reply With Quote
 
Hans Mulder
Guest
Posts: n/a
 
      11-30-2010
Giacomo Boffi wrote:
> Terry Reedy <(E-Mail Removed)> writes:
>
>> On 11/28/2010 3:47 PM, (E-Mail Removed) 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.

>
> In 3.x, are Tkinter classes still derived by old-style classes?


3.x does not provide old-style classes.

Oh, and the name Tkinter was changed to tkinter: all modules in the
standard library have lower case names in 3.x.

HTH,

-- HansM
 
Reply With Quote
 
Robert Kern
Guest
Posts: n/a
 
      11-30-2010
On 11/30/10 11:00 AM, Giacomo Boffi wrote:
> Terry Reedy<(E-Mail Removed)> writes:
>
>> On 11/28/2010 3:47 PM, (E-Mail Removed) 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.

>
> In 3.x, are Tkinter classes still derived by old-style classes?


No.

[~]$ python3
Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:1
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> tkinter.Tk.mro()

[<class 'tkinter.Tk'>, <class 'tkinter.Misc'>, <class 'tkinter.Wm'>, <class
'object'>]
>>>


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does friendship extend to inner classes? Juha Nieminen C++ 9 06-13-2011 04:46 PM
How to extend inner classes? harold fellermann Python 0 12-21-2004 01:40 PM
How to extend inner classes? Kay Schluehr Python 0 11-28-2004 03:17 PM
How to extend inner classes? Kay Schluehr Python 1 11-28-2004 12:58 PM
How to extend inner classes? hfellerm@uni-osnabrueck.de Python 0 11-27-2004 05:02 PM



Advertisments