[Tutor] Rather vague questions.... (Tkinter)

Michael P. Reilly arcege@shore.net
Wed, 14 Feb 2001 07:32:31 -0500 (EST)


>   Hi all,
> 
>   I have gotten this error, while running a little python program I am =
> creating as a project.  Here is the error :
> 
> Traceback (most recent call last):
>   File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball =
> game.py", line 264, in gogamego
>     Screen.coords(ballphys, Ball.x1, Ball.y1, Ball.x2, Ball.y2) #the =
> reassigning of the ball's coords
>   File "c:\python20\lib\lib-tk\Tkinter.py", line 1929, in coords
>     self.tk.splitlist(
> TclError: invalid command name ".22703164"
> 
>   It's an error which pops up in the interactive window every time the =
> program quits.  It could have something to do with the thread still =
> running and thus losing all the objects it was referencing - but I don't =
> know enough about the error messages to tell if this is the case.
>   Sometimes (damn intermittent errors) the main thread of the program =
> quits (I think...I should probably trap the exit() call...) for no =
> reason.  I am hoping that it has something to do with this error.  It =
> seems the faster I make the thread run the sooner it quits, and I can =
> almost get it to quit every single time I run it at a fast speed (with a =
> 0.0025 second delay between each iteration) it breaks every time.  When =
> it does this, it shows a different error to the one above, it shows this =
> one :

Yes, without the code there is only so much we can do to help you, but
here are some things to thing about.

First, Tkinter will only work "well" if it is running in the main
(first) thread.  You can delegate other functionality to the additional
peer threads, but you'll run into problems (likely the ones you've
seen).  You might want to do some searches in the archives at
www.python.org/search.

Second, it is often not necessary to have separate threads.  Most
things that will need to be done are just at specific intervals
(updating non-player "enemies", etc.).  Those can be done with the
after() and after_idle() methods instead of using threads.

Threads lead to complications with data integrity, indefinate
postponement and deadlock, to name just a few issues involved.  Please
make sure that you NEED threads before you think to use them; you'll
find that your programming needs to much more complex.

But even if you think you need threads, make sure that Tkinter is in
the main thread.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------