title: When do I need to call mainloop in a Tkinter application?
body: <p>Every tkinter tutorial I have seen claims that <code>tkinter.mainloop</code> must be called for windows to be drawn and events to be processed, and they always call this function, even in hello world programs.  However, when I try these out in the interactive shell, windows are drawn correctly without having to call mainloop.  <a href="http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk.html" rel="noreferrer">This example</a> of embedding matplotlib graphics in tkinter produces a relatively complex application, with buttons for panning, zooming and resizing a plot within a tkinter window, and again, this all works if you remove the call to mainloop and run the code in the interactive shell.  Of course, if I run the script (with mainloop removed) outside the interactive shell, the program ends too quickly to see what happens, but if I add a call to <code>input</code> to hold the program open everything works correctly (I'm running python 3.2.2 on linux).</p>
  
  <p>So what exactly does mainloop do, and when is it necessary to call it?</p>
  
  <p>EDIT:
  To clarify, if I open up the GNOME terminal and type</p>
  
  <pre><code>$python3
  &gt;&gt;&gt; import tkinter
  &gt;&gt;&gt; root = tkinter.Tk()
  </code></pre>
  
  <p>a window immediately appears without having to call mainloop, and more complex tkinter functionality seems to work as well (for example, adding buttons to the window).  In IDLE, a call to mainloop is necessary.  It was my understanding that nothing should be drawn, and no events should be processed, until mainloop is called.</p>