pygtk, threads and the Game of Life

Rajarshi Guha rajarshi at presidency.com
Thu Dec 5 16:00:59 EST 2002


HI,
  I'm new to threads and am trying to program a Game Of Life with PyGTK
and threads. The structure of my program is as follows:

class GUIThread(Thread):
  
  def __init__(self):
   Thread.__init__(self)
  
  def run(self):
   # Create GUI
   gtk.mainloop()

if __name__ == '__main__':
  g = GUIThread()
  g.run()
  for i in range(0,1000): print i

Now, I expected that the program would draw a window with a grid and
randomly fill in boxes and also print out the numbers from 1 to 1000 in
the console window. However, only the GUI shows and the numbers dont get
printed.

I think I should be using an idle function - but I was'nt sure how to
implement it. Basically I not very clear as to how I can iterate over an
array and each time an element changes change the corresponding grid in
the GUI. I though that I could start up the GUI in a thread and let it
run in the background. Meanwhile in the foreground I would iterate over
the array and change the GUI display when required. But it does'nt seem
to be working.

Can anybody point out the proper path to take?

Thanks,



More information about the Python-list mailing list