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

Discussion in 'Python' started by Terry Reedy, Nov 28, 2010.

  1. Terry Reedy

    Terry Reedy Guest

    On 11/28/2010 3:47 PM, 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
     
    Terry Reedy, Nov 28, 2010
    #1
    1. Advertising

  2. On Nov 29, 12:15 am, Terry Reedy <> wrote:
    > On 11/28/2010 3:47 PM, 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
     
    Michele Simionato, Nov 29, 2010
    #2
    1. Advertising

  3. Terry Reedy

    Guest

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

    Michele and Terry,

    > From: "Michele Simionato" <>
    >
    > 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
     
    , Nov 29, 2010
    #3
  4. Re: Using property() to extend Tkinter classes but Tkinter classes are old-style classes?

    Terry Reedy <> writes:

    > On 11/28/2010 3:47 PM, 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?
     
    Giacomo Boffi, Nov 30, 2010
    #4
  5. Terry Reedy

    Hans Mulder Guest

    Giacomo Boffi wrote:
    > Terry Reedy <> writes:
    >
    >> On 11/28/2010 3:47 PM, 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
     
    Hans Mulder, Nov 30, 2010
    #5
  6. Terry Reedy

    Robert Kern Guest

    On 11/30/10 11:00 AM, Giacomo Boffi wrote:
    > Terry Reedy<> writes:
    >
    >> On 11/28/2010 3:47 PM, 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:18)
    [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
     
    Robert Kern, Nov 30, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dlo_olb
    Replies:
    2
    Views:
    2,348
    Fredrik Lundh
    Jun 25, 2003
  2. G Fernandes

    is this definition old-style or new-style

    G Fernandes, Feb 27, 2005, in forum: C Programming
    Replies:
    8
    Views:
    457
    Andrey Tarasevich
    Mar 1, 2005
  3. Kza
    Replies:
    4
    Views:
    434
    Andrew Koenig
    Mar 3, 2006
  4. john
    Replies:
    8
    Views:
    382
    Nick Keighley
    Jun 22, 2010
  5. Jayden
    Replies:
    9
    Views:
    308
    alex23
    Sep 27, 2012
Loading...

Share This Page