title: invalid command name ".!canvas"
body: <p>I'm attempting to create a canvas with 100 completely random rectangles appearing, but what I get is a blank canvas and an error:</p>
  
  <p>invalid command name ".!canvas"</p>
  
  <p>How do i fix this?</p>
  
  <pre><code>from tkinter import *
  import random
  tk = Tk()
  canvas = Canvas(tk, width=400, height=400)
  canvas.pack()
  tk.mainloop()
  
  def rndm_rect(width, height):
      x1 = (random.randrange(width))
      y1 = (random.randrange(height))
      x2 = x1 + (random.randrange(width))
      y2 = y1 + (random.randrange(width))
      canvas.create_rectangle(x1, y1, x2, y2)
  
  rndm_rect(400, 400)
  
  
  for x in range(0, 100):
      rndm_rect(400, 400)
  </code></pre>