On Mon, 11 Jun 2012, Mark Summerfield wrote:
Hi,
For tkinter methods that take 0 or 1 for true or false such as
wm_overrideredirect(), is it safe to use Python's True and False
builtins instead?
Doing so seems to work, but just wanted to check.
I'm somewhat certain that it will work just fine, at least it does everywhere
I've used it. My guess is the reason that it does work is because of Python's
truthiness checks - 1, and any collection (string, list, tuple, set, dict...
etc) that contain values are True. 0, None, and all empty collections are
False.
This makes it possible to write cleaner code (at least in my, and many other
people's opinion) because instead of having to write:
if len(mylist) == 0:
#blah blah blah
you can just write
if mylist:
#blah blah blah
Which might surprise someone at first, but I think most (all?) people find it
incredibly natural to use.
I haven't done any tests, but I would make a guess that [Tt]kinter might do a
truthiness conversion before passing the argument on to Tcl. At least in every
case that I've used it it does for values of 1 and True...
HTH,
Wayne
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss