[Tkinter-discuss] Strange behavior with python 2.5

Michael Lange klappnase at web.de
Mon Nov 17 22:08:13 CET 2008


On Sun, 16 Nov 2008 19:21:34 -0200
"Guilherme Polo" <ggpolo at gmail.com> wrote:

> On Sun, Nov 16, 2008 at 6:59 PM, Michael Lange <klappnase at web.de> wrote:
> > On Sun, 16 Nov 2008 17:18:54 -0200
> > "Guilherme Polo" <ggpolo at gmail.com> wrote:
> >
> >> On Sun, Nov 16, 2008 at 4:59 PM, Vasilis Vlachoudis
> >> <Vasilis.Vlachoudis at cern.ch> wrote:
> >> > Finally I didn't understand, is it a problem of Tkinter or Tk/Tcl?
> >>
> >> It is not really a problem. But if you want to blame someone, go for
> >> Python then.
> >>
> >
> > If you get unexpected and , if the software you write is supposed to run on
> > different platforms, also unpredictable behavior like this I think it *is* a
> > problem.
> 
> I meant more in these sense of the conversion raising some exception,
> but it can be seen in that way too sure. But this doesn't depend on
> the platform, all them will show this behaviour.
> 

O.k., by "platform" I actually meant different linux / unix systems with
different versions of Python / Tk installed.

(...)

> 
> Good for you then :)
> It gets hard to continue arguing about this now, since you apparently
> solved the question on your side and thus won't have real examples of
> this problem, and why it couldn't be solved, anymore (or maybe you do,
> so we can continue on this).

Using Tk-8.5 it is not too hard to find examples:

>>> from Tkinter import *
>>> root = Tk()
>>> t = Text(root)
>>> t.pack()
>>> t.insert('end', 'foobar')
>>> i = t.index('end')
>>> i
<textindex object at 0x81e0ba8>
>>> print i
2.0
>>> int(i)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string or a number, not '_tkinter.Tcl_Obj'
>>> str(i)
'2.0'

> 
> > The problem is that you never seem
> > to know where the TclObjects appear on Python / Tk versions other than your own.
> > So what else to do? Convert everything Tk returns to string?
> 
> No, like I said, who calls into _tkinter should know what kind of
> object to expect so you do the conversion yourself. If you are going
> to return the object to the user, then surely check if it is what you
> are expecting it to be.
> 
> Now, I'm sure this can be improved in Python but you have to invest
> some time on it.

So you mean, the only option to fix this is to write patches for Tkinter.py,
resp. the other modules in lib-tk, so the return values of "broken" methods
are converted from TclObjects into string (or whatever seems adequate)?

Michael


More information about the Tkinter-discuss mailing list