Advertisement
Guest User

runlife.py

a guest
Sep 17th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import Tkinter, sys, life, util
  2.  
  3. #runlife.py
  4.  
  5.  
  6. boardFile = sys.argv[1]
  7.  
  8. game = life.Life(util.loadBoard(boardFile))
  9.  
  10. root = Tkinter.Tk()
  11. root.wm_title("Life!!!")
  12.  
  13. cells = [[0 for x in range(game.getNumRows())] for y in range(game.getNumCols())]
  14.  
  15. for r in range(game.getNumRows()):
  16.   for c in range(game.getNumCols()):
  17.     alive = game.isAlive(r,c)
  18.     color = ""
  19.     if alive:
  20.       color = "white"
  21.     else:
  22.       color = "black"
  23.     cells[r][c] = Tkinter.Canvas(root, background=color, width=12, height=12, borderwidth=0)
  24.     cells[r][c].grid(row=r,column=c)
  25.            
  26. def animate():
  27.   updateBoard()
  28.   game.runTimeStep()
  29.   root.after(500, animate)
  30.  
  31. def updateBoard():
  32.   for r in range(game.getNumRows()):
  33.     for c in range(game.getNumCols()):
  34.         alive = game.isAlive(r,c)
  35.         color = ""
  36.         if alive:
  37.           color = "white"
  38.         else:
  39.           color = "black"
  40.         cells[r][c].configure(background=color)
  41.  
  42. animate()
  43. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement