title: Turtle Graphics Python, .mainloop()
body: <p>I am programming in Python and I have a few questions that I can't find the answer to anywhere (please read all questions as they build up to my last question):</p>
  
  <p>1.What Does the <code>.mainloop()</code> really do? I read the all the answers in Stack Overflow, I also checked the documentations explanation.</p>
  
  <p>2.Does the <code>.mainloop()</code> always have to be at the end of a turtle program?</p>
  
  <p>3.I have used <code>.mainloop()</code> before. My question is, if I have the f.f.g code:</p>
  
  <pre><code>import turtle
  
  screen = turtle.Screen()
  alex =  turtle.Turtle()
  tess = turtle.Turtle()
  
  def yes(x, y):
      alex.onclick(yes)
      print("Hello World")
  
  tess.onclick(yes)
  turtle.mainloop()
  </code></pre>
  
  <p>Why does alex get an action event when the function <code>yes()</code> is run? I know it does because the function is called, but what is actually happening? I mean the statement <code>turtle.mainloop()</code> is run before tess is clicked, and tess's action event is waited for in the event loop, so how does alex's event get in the event loop since its statement is run after <code>turtle.mainloop()</code> is run?</p>