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

Glen Wheeler wheelege@tsn.cc
Thu, 15 Feb 2001 08:02:25 +1100


  Thanks for the quick reply. I've now got :

Traceback (most recent call last):
  File "C:\WINDOWS\Profiles\Glen\Desktop\etc\pystuff\the bouncy ball
game.py", line 266, 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 ".21933052"

  Nutted out.  That was the exception  occuring if the main thread
unexpectedly quit (ie no break command or natural end), and I found the
error that made it occur.  I replaced another thread I had (now I onyl have
one thread) which created other things for you to play with, and replaced it
with a whole load of event bindings.  Seems to work better now.
  However, the other error I was getting seems to have run off from my
program.  I cannot recreate it.  That was a problem because it would only
occur at high speeds, and would crash the whole thing.  Maybe it was to do
with my computer not being restarted in a long long time.  Whatever it was,
be sure I'll post it again (along with some code, if it looks nicer by then)
because I will not have any idea how it came about.
  I really do need at least one thread, but I think I can do other minor
operations not with threads.  I've read a bit about them, and the docs are
not hugely confident in their stability (hey who would be).  I think I'm
going to have to do some more fiddling with little baby thread
applications - I strongly suspect the reason I was getting the error about
float() was because a floating point variable used in the same while loops
as that command was confused with an integer - but I'm not sure.  I hope
that isn't true because if it is I have no idea how to fix it.

  Thanks again,
  Glen.


----- Original Message -----
From: Michael P. Reilly <arcege@shore.net>
To: Glen Wheeler <wheelege@tsn.cc>
Cc: <tutor@python.org>
Sent: Wednesday, February 14, 2001 11:32 PM
Subject: Re: [Tutor] Rather vague questions.... (Tkinter)


> >   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             |                                |
> ------------------------------------------------------------------------