Python 2.3b1 and _tkinter.Tcl_Obj
Stephen D Evans
sde at recombinant.demon.co.uk
Wed Apr 30 14:01:00 EDT 2003
Is this Python or Tk/Tcl? Is it a bug or a feature?
There are some inconsistencies in the types returned by some Tkinter widgets
when using cget() or configure() e.g.
widget.cget('background')
Menu widgets return a Tcl_Obj (typename='border'), Buttons return a string.
The following code demonstrates using configure() rather than cget()
# Python 2.3b1 (#40, Apr 25 2003, 19:06:24) [MSC v.1200 32 bit (Intel)] on
win32
#
import Tkinter
import _tkinter
import types
# workaround
#Tkinter.wantobjects = 0
for name in Tkinter.__dict__:
c = getattr(Tkinter, name)
if isinstance(c, types.ClassType) and Tkinter.Widget in c.__bases__:
widget = c()
tup = widget.configure('background')[3:] # last two
print c, type(tup[0]), type(tup[1])
assert 2 == len(tup)
for i in tup:
assert isinstance(i, (types.StringType, _tkinter.Tcl_Obj))
assert not isinstance(i, _tkinter.Tcl_Obj) or i.typename ==
'border'
#-----------------------
I found this while fiddling with the Pmw megawidget (http://pmw.sf.net)
tests and demos
under Python 2.3b1
Stephen D Evans
More information about the Python-list
mailing list