This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author shippo_
Recipients epaine, serhiy.storchaka, shippo_
Date 2020-12-26.19:29:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
There are 2 good reasons for making Tk variables comparable by value:

   1. We honor the equality operator! The equality operator (==) has to compare two objects by value. The current implementation does not fulfil this. Yes, if two Tk variables have the same names in the Tcl interpreter, they are guaranteed to have the same value.

>>> a = tk.IntVar(name='a')
>>> b = tk.IntVar(name='a')
>>> assert a == b  # this is not enough; equality means "by value"
                   # what about when they don't have the same name?

>>> assert a is not b  # this again does not make sense, since
                       # both Python "a" and "b" identifiers lead to
                       # the same "self._tk.globalgetvar(self._name)"
                       # Tcl registered variable: name="a"

>>> a.set(42); assert b.get() == a.get() == 42  # yes!
    # equality in names guarantees equality in value

Yes ... BUT, the negation is not true: if two Tk variables have different names, that does NOT mean that they have different values. This is where we fail the equality operator:

>>> c = tk.IntVar(name='c', value=42)
>>> assert a._name != c._name and a.get() != c.get(), \
...     "Difference in names does not guarantee difference in value"

   2. When we're interested in Tk variable comparison: .get() becomes redundant. Every time two Tk variables are of the same type AND they refer to the same value, we can safely compare them as equal, regardless of how they are named in the Tcl interpreter.
Date User Action Args
2020-12-26 19:29:16shippo_setrecipients: + shippo_, serhiy.storchaka, epaine
2020-12-26 19:29:16shippo_setmessageid: <>
2020-12-26 19:29:16shippo_linkissue42750 messages
2020-12-26 19:29:16shippo_create