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 klappnase
Recipients gpolo, klappnase, mark, roger.serwy, terry.reedy
Date 2012-06-24.11:19:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1340536750.09.0.554415511975.issue15133@psf.upfronthosting.co.za>
In-reply-to
Content
The behavior of Tkinter when handling boolean values appears to be a bit erratic at times, not only BooleanVar.get() returns 0/1 instead of True/False (e.g. see the thread at tkinter-discuss: http://mail.python.org/pipermail/tkinter-discuss/2012-June/003176.html ). This is apparently because tk itself uses the strings '0' and '1' as boolean values, so behind the scenes Tkinter has to convert any bool into a string when setting a value and the string back into a bool when retrieving it, and it seems like most of the Tkinter code (and docstrings) was written in the good ol' days when Python used 0 / 1 itself.
Now when it comes to change Tkinter's behavior I'd tend to be careful. For example BooleanVar.get() could easily be changed to always return True/False. But imho this change would only make sense if you add strict input value checking for set() either, otherwise we just change one incoherency with another. But this would mean that we might end up breaking a lot of working code, for what seems to me a primarily aesthetic reason.

And of course, I don't see much use in isolated changes of the behavior of one function here and another method there. I feel that if the behavior of Tkinter concerning bool values was to be changed, there should at least be a thorough change of *any* Tkinter method that gets / sets boolean values so we at least end up with an overall coherent solution.
But again, this looks like quite a lot of work, will break running code and add no significant benefit besides a cosmetic improvement.
So my vote goes to accepting that 0 and 1 are ok boolean values in Tkinter and changing no more than misleading docstrings, as in this example of BooleanVar.get():

    def get(self):
        """Return the value of the variable as 1 (True) or 0 (False)."""
        return self._tk.getboolean(self._tk.globalgetvar(self._name))
History
Date User Action Args
2012-06-24 11:19:10klappnasesetrecipients: + klappnase, terry.reedy, mark, gpolo, roger.serwy
2012-06-24 11:19:10klappnasesetmessageid: <1340536750.09.0.554415511975.issue15133@psf.upfronthosting.co.za>
2012-06-24 11:19:09klappnaselinkissue15133 messages
2012-06-24 11:19:08klappnasecreate