klappnase <klappn...@web.de> added the comment:

I agree that get() should better return a boolean in any case, however the bug 
then is not one of BooleanVar but rather one of tk.getboolean(). I did some 
experimenting with get() and it seems that there are three possibilities: 
getboolean() returns True/False as it should when the variable value was 
previously set() to anything Tcl accepts as boolean value (like 'yes'/'no', 
'0'/'1', 'on'/'off', 'true'/'false'). If something which is not a proper 
Tcl-bool was passed to set() before, getboolean will produce a TclError or 
TypeError.
If set() got 0/1 (as integers) or True/False before, getboolean() will return 
0/1 and this appears to me to be the only bug here. But this is not at all a 
sole BooleanVar bug, e.g.:

>>> root=Tk()
>>> root.tk_strictMotif()
0
>>> root.tk_strictMotif(1)
1

You will find this everywhere in Tkinter where getboolean() is used, so I think 
that rather this should be fixed in _tkinter.c than applying a workaround to 
BooleanVar.get() and leaving all other uses of getboolean() as they are; even 
worse, if BooleanVar.set() was changed to accept only True/False and 
getboolean() left as it is, you could not pass the return value of getboolean() 
any longer to BooleanVar.get() which would be really bad.

As far as set() is concerned, it should at least allow everything that Tcl 
accepts as boolean, according to http://wiki.tcl.tk/16235 these are at least 
the above mentioned 'yes'/'no', '0'/'1', 'on'/'off', 'true'/'false' (btw. all 
of these seem to be ok even case insensitive on the tcl side) plus of course 
0/1 and True/False. Otherwise it might break existing code. 

Terry:
"Since the purpose of Variables is to synchronize values between user code and 
tk, TypeVar().set(x).get() should be x when has the proper type. That is now 
true for everything but bool/Boolean."
But when the input type is not proper you can do e.g.:

>>> d = DoubleVar()
>>> d.set('1.1')
>>> d.get()
1.1
>>> i = IntVar()
>>> i.set(True)
>>> i.get()
1
>>> 

I think the Variable classes can also be considered convenience objects that 
save the application programmer a lot of headaches when they have to convert 
Python objects into Tcl which usually expects strings, so I think there is 
nothing wrong with set() accepting "improper" values.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15133>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to