From: Dave Angel on
Alan G Isaac wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">On
> 6/24/2010 1:59 AM, Dennis Lee Bieber wrote:
>> It is NOT a numeric "variable" in Python realms.
>
> Sure, but why does it not behave more like one?
> It seems both obvious and desirable, so I'm
> guessing there is a good reason not to do it.
>
>> So var+=increment can't be used because Python would rebind the name
>> var to a new object
>
>>>> import Tkinter as tk
>>>>
>>>> class IntVar2(tk.IntVar):
> ... def __iadd__(self, val):
> ... self.set(self.get()+val)
> ... return self
> ...
>>>> root = tk.Tk()
>>>> myintvar2 = IntVar2()
>>>> temp = myintvar2
>>>> myintvar2 += 5
>>>> print(myintvar2.get(),myintvar2 is temp)
> (5, True)
>
> Alan Isaac
>
A real Python integer is immutable. But for tkinter, you want something
that can change. So they define an object that can be changed. But the
default behavior of += is to assign a new object with the new value,
rather than changing the previous object.

DaveA

From: Alan G Isaac on
On 6/25/2010 1:14 PM, Dave Angel wrote:
> the default behavior of += is to assign a new object with the new value,
> rather than changing the previous object.

>>> a = []
>>> temp = a
>>> a += [2]
>>> temp
[2]

Alan Isaac

From: Alan G Isaac on
On 6/25/2010 1:24 PM, rantingrick wrote:
> the "if __name__ == '__main__' tests" use
> root.quit instead of root.destroy!

Did you open an issue?
http://bugs.python.org/

Alan Isaac

From: Dave Angel on
Alan G Isaac wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">On
> 6/25/2010 1:14 PM, Dave Angel wrote:
>> the default behavior of += is to assign a new object with the new value,
>> rather than changing the previous object.
>
>>>> a = []
>>>> temp = a
>>>> a += [2]
>>>> temp
> [2]
>
> Alan Isaac
>
>
I said "default", not "only" behavior. I suspect list provides an
__iadd__ method to provide this ability. Integers do not, and
therefore neither does the object the OP was asking about.

DaveA
From: Terry Reedy on
On 6/25/2010 10:12 AM, Alan G Isaac wrote:
> On 6/24/2010 1:59 AM, Dennis Lee Bieber wrote:
>> It is NOT a numeric "variable" in Python realms.
>
> Sure, but why does it not behave more like one?
> It seems both obvious and desirable, so I'm
> guessing there is a good reason not to do it.

tkinter was written long before newstyle classes and properties existed.
For 3.x, all the classes had to be and were updated. I presume
properties could now be used in 3.x to update the interface.

--
Terry Jan Reedy