[Tutor] Running Python GUI on Windows and Linux...problems encountered in Windows.

wheelege wheelege@tsn.cc
Fri, 7 Sep 2001 18:40:56 +1000


  Hi,

  I had similar problems with a tkinter game I developed for the place I
work for (pong+arkanoid, networked scores, network multiplayer...etc) and I
had hell with this exact error.
  The way to fix it is to do >zero< GUI calls in any thread other than the
main one.  This is a little trickier than it sounds, but very possible.

> <...>
>
>
> class VirtualHandSetProcessor:
>     def __init__(self):
>         self.handset = VirtualHandSet()
> #        self.Pipe = TcpIpPipe()
>         thread.start_new_thread(self.WorkerThread, ())
>
>     def WorkerThread(self):
>         while(1):
>             print 'Hello'
>             print self.handset.GetEventQ()
>             sleep(1)

  I didn't use this exact architecture but I think here is where your
problem may lie.
  You have the same instance of a class with two threads - one which is
heavy GUI and one which looks like it has only processing.  However, with
the line 'print self.handset.GetEventQ()' you are accessing a function from
an object which is in use by the other main GUI thread, for GUI type calls.
This is what I think you need to fix.
  Perhaps use a dummy object with some attributes (no GUI stuff) and get the
while 1 loop to check it's attributes for changes instead of polling the
handset object (of the VirtualHandSet class).  This would mean that whenever
an event occured you would have to append it to the dummy object instead of
itself, but this should be only a minor code change.
  I'll just append this discaimer here - I did not use this exact object
structure so I may well be wrong :)

>
>
>
> if __name__ == '__main__':
>     print "Hello"
>     a = VirtualHandSetProcessor()
>     print "Hello"
>