[Python-bugs-list] [ python-Bugs-671741 ] Tk.IntVar.get fails after set(True) in 2.3a1
SourceForge.net
noreply@sourceforge.net
Wed, 22 Jan 2003 01:22:47 -0800
Bugs item #671741, was opened at 2003-01-21 13:06
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=671741&group_id=5470
Category: Python Library
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Edward K. Ream (edream)
Assigned to: Nobody/Anonymous (nobody)
Summary: Tk.IntVar.get fails after set(True) in 2.3a1
Initial Comment:
Executing the following fails in 2.3a1. Similar code
works in 2.1 and 2.2.
def truebug():
import Tkinter
Tk = Tkinter
top = Tk.Toplevel()
f = Tk.Frame(top)
f.pack()
var = Tk.IntVar()
box = Tk.Checkbutton(f, anchor="w",
text="box",variable=var)
box.pack()
var.set(True)
val = var.get()
Example:
Microsoft Windows XP [Version 5.1.2600]
...
Python 2.3a1 (#38, Dec 31 2002, 17:53:59) [MSC
v.1200 32 bit (Intel)] on win32
...
>>> import truebug
>>> truebug.truebug()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "c:\prog\test\truebug.py", line 15, in truebug
val = var.get()
File "C:\PYTHON23\lib\lib-tk\Tkinter.py", line 239, in get
return getint(self._tk.globalgetvar(self._name))
ValueError: invalid literal for int(): True
>>>
Edward
--------------------------------------------------------------------
Edward K. Ream email: edream@tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------
----------------------------------------------------------------------
>Comment By: Martin v. Löwis (loewis)
Date: 2003-01-22 10:22
Message:
Logged In: YES
user_id=21627
This is now fixed in
Tkinter.py 1.169
_tkinter.c 1.148
I've also changed BooleanVar.get (indirectly) to return bool
objects.
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2003-01-21 23:46
Message:
Logged In: YES
user_id=21627
A BooleanVar won't work for a checkbutton: The -variable
argument must have either -onValue or -offValue, which
default to 0/1.
I do think that an IntVar should accept booleans in .set,
and translate them into 0/1.
A slightly related bug is that .get of a BooleanVar should
probably return False/True, not 0/1.
----------------------------------------------------------------------
Comment By: Edward K. Ream (edream)
Date: 2003-01-21 23:10
Message:
Logged In: YES
user_id=14056
Thanks for the explanation. I shall indeed use a BooleanVar.
However, it would be nice if tkinter could do what it did
before...
I asked about this behavior on comp.lang.python and Martin
v. Löwis said he thought it was a bug. I'll let you two fight it
out :-)
Edward
----------------------------------------------------------------------
Comment By: Christos Georgiou (tzot)
Date: 2003-01-21 20:59
Message:
Logged In: YES
user_id=539787
First thought: why not use a BooleanVar?
The problem is that if you do a var.set(True), _tkinter
translates the argument into a string (_tkinter.c, function
SetVar after some levels of calling), because I think
everything in tcl is a string. In Python pre-2.2.2, str(True) was
still "1".
What you get in your case by var.get, is the string "True"
(try
print int("True")
or, if you check the Tkinter.py script, try at the end of your
example:
m= var._tk.globalgetvar(var._name)
and check the type of m.
Resolving this (to allow a bool in an IntVar), one could
override Tkinter.IntVar.set, perhaps, to allow boolean
arguments for integer variables (just converting to int before
calling the Tkinter.Variable.set).
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=671741&group_id=5470