title: Python Tkinter refresh canvas
body: <p>Hello I have a tuple  in python with colours that are related to squares that are drawn in the canvas by the following dictionary: </p>
  
  <pre><code>colour_mapping = {0: "red", 1: "green", 2: "blue" , 3:"purple"}
  </code></pre>
  
  <p>To be more specific for example a node at the tuple is:</p>
  
  <pre><code>((2, 3), (3, 3))
  </code></pre>
  
  <p>This means that 4 squares should be drawn this way:</p>
  
  <pre><code>blue square    purple square
  purple square     purple square
  </code></pre>
  
  <p>and then their colours should be changed accordingly to the next node in my tuple</p>
  
  <p>To do this I iterate the tuple and for each element I draw a new rectangle at the canvas and then I call the <code>time.sleep()</code> function in order to give time to the user to see the differences to the previous state.
  My problem is that only the last node is rendered correctly while all the others aren't shown. Can you help me?</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>self.parent.title("AlienTiles")
  self.style = Style()
  self.style.theme_use("default")
  
  self.frame =  Frame(self, relief=RAISED, borderwidth=1)
  self.frame.pack(fill=BOTH, expand=1)
  
  self.canvas = Canvas(self.frame)
  self.canvas.pack(fill=BOTH, expand=1)
  
  self.pack(fill=BOTH, expand=1)
  
  
  for i in range(len(path)) : #the tuple is path
  
              state = path[i].state
              print state
              time.sleep(1)
              y_offset=10
              for x in state:
                  start_x=40
                  start_y=10
                  i=1
                  x_offset=0
  
                  for y in x:
  
                      x0=(start_x*i)+x_offset
                      y0=(start_y*i)+y_offset
                      x1=x0+size
                      y1=y0+size
                      colour=colour_mapping[y]
  
                      print colour
  
                      self.canvas.create_rectangle(x0, y0, x1, y1, fill=colour)
                      x_offset=x_offset+size+10
  
  
                  y_offset=y_offset+size+10
  </code></pre>
  
  <p>All in all, I try to make an animation described above. Is there anything I don't think correctly or something to refresh the canvas at each loop?</p>