title: Python tkinter canvas going slow
body: <p>This is Life Game code and I thought there is no problem and it works.</p>
  
  <p>However, when I 'start' it, it`s drawing speed gets slower and slower.</p>
  
  <p>I want to know why it`s speed is slowing down.</p>
  
  <pre><code># -*- coding: cp949 -*-
  import Tkinter
  from time import sleep
  
  def check():
      """count alive neighbor cells and save it in list 'neighbor'
      """
      global lifegame
      global neighbor
      global indexx
      global indexy
      for y in range(0, indexy):
          for x in range(0, indexx):
              neighbor[y][x] = 0
      for y in range(0, indexy):
          for x in range (0, indexx):
              try:
                  if lifegame[y-1][x-1] == 1:
                      neighbor[y][x] += 1
                  if lifegame[y][x-1] == 1:
                      neighbor[y][x] += 1
                  if lifegame[y+1][x-1] == 1:
                      neighbor[y][x] += 1
                  if lifegame[y-1][x] == 1:
                      neighbor[y][x] += 1
                  if lifegame[y+1][x] == 1:
                      neighbor[y][x] += 1
                  if lifegame[y-1][x+1] == 1:
                      neighbor[y][x] += 1
                  if lifegame[y][x+1] == 1:
                      neighbor[y][x] += 1
                  if lifegame[y+1][x+1] == 1:
                      neighbor[y][x] += 1
              except IndexError:
                  continue
  
  def change():
      """
      check neighbor num, and change lifegame
      cell`s state 0 to 1 or 1 to  0
      """
      global lifegame
      global neighbor
      global indexx
      global indexy
      for y in range(0, indexy):
          for x in range(0, indexx):
              if lifegame[y][x] == 0:
                  if neighbor[y][x] == 3:
                      lifegame[y][x] = 1
                  else: continue
              elif lifegame[y][x] == 1:
                  if neighbor[y][x]&lt;2 or neighbor[y][x]&gt;3:
                      lifegame[y][x] = 0
                  else: continue
  
  def stop():
      """
      go is  variable to stop while loop
      """
      global go
      go = False
  
  def start():
      """
      go is  variable to stop while loop
      """
      global go
      go = True
      checkgo()
  
  def checkgo():
      "when go is true, do while loop that will draw in canvas"
      global go
      while go:
          check()
          change()
          draw()
      print "end"
  
  def reset():
      """kill all cells and reset"""
      global go
      global lifegame
      global neighbor
      global indexx
      global indexy
      go = False
      for y in range(0, indexy):
          for x in range(0, indexx):
              neighbor[y][x] = 0
              lifegame[y][x] = 0
      draw()
  
  def callback(event):
      """mouse click event"""
      global go
      go = False
      print "clicked at", event.x / 10, event.y / 10
      a = event.x / 10
      b = event.y / 10
      global lifegame
      global neighbor
      if lifegame[b][a] == 0:
          lifegame[b][a] = 1
      elif lifegame[b][a] == 1:
          lifegame[b][a] = 0
      check()
      draw()
  
  def draw():
      """draw cells on canvas"""
      global lifegame
      global indexx
      global indexy
      global tk
      for y in range(0, indexy):
          for x in range(0, indexx):
              if lifegame[y][x] == 0:
                  canvas.create_polygon(10*x, 10*y, 10*x, 10+10*y, 10+10*x,
                                        10+10*y, 10+10*x, 10*y, fill='white')
              elif lifegame[y][x] == 1:
                  canvas.create_polygon(10*x, 10*y, 10*x, 10+10*y, 10+10*x,
                                        10+10*y, 10+10*x, 10*y, fill='black')
      tk.update()
  
  lifegame = []
  neighbor = []
  tk = Tkinter.Tk()
  indexx = 10
  indexy = 10
  go = False
  for a in range(0, indexy):
      lifegame.append([0]*indexx)
      neighbor.append([0]*indexx)
  menubar = Tkinter.Menu(tk)
  optionmenu = Tkinter.Menu(menubar, tearoff=0)
  optionmenu.add_command(label="Start", command=start)
  optionmenu.add_command(label="Stop", command=stop)
  optionmenu.add_command(label="Reset", command=reset)
  optionmenu.add_separator()
  optionmenu.add_command(label="Exit", command=tk.quit)
  tk.config(menu = menubar)
  menubar.add_cascade(label="Option", menu=optionmenu)
  canvas = Tkinter.Canvas(tk, width=300, height=300)
  canvas.pack()
  canvas.bind("&lt;Button-1&gt;", callback)
  draw()       
  tk.mainloop()
  </code></pre>