title: Python Tkinter window.mainloop()
body: <p>I have copied the following code to experiment with animations using Tkinter:</p>
  
  <pre><code>from Tkinter import *
  window = Tk()
  canvas = Canvas(window, width = 400, height = 300)
  canvas.pack()
  x0 = 10
  y0 = 50
  x1 = 60
  y1 = 100
  i = 0
  deltax = 2
  deltay = 3
  which = canvas.create_oval(x0,y0,x1,y1,fill="red", tag='redBall')
  while True:
      canvas.move('redBall', deltax, deltay)
      canvas.after(20)
      canvas.update()
      if x1 &gt;= 400:
          deltax = -2
      if x0 &lt; 0:
          deltax = 2
      if y1 &gt; 300:
          deltay = -3
      if y0 &lt; 0:
          deltay = 3
      x0 += deltax
      x1 += deltax
      y0 += deltay
      y1 += deltay
  window.mainloop()
  </code></pre>
  
  <p>This works fine, but what I have noticed is that it seems to work the same with and without the line <code>window.mainloop()</code>. Furthermore, this line seemingly would never be called, because the prevailing <code>while</code> loop never breaks. However, I have seen this example code many times, so it seems that <code>window.mainloop()</code> does perform something important. What is that thing??</p>