Turtle Graphics Python, .mainloop()
<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 .mainloop() really do?I read the all the answers in Stack Overflow, I also checked the documentations explanation.</p>

<p>2.Does the .mainloop() always have to be at the end of a turtle program?</p>

<p>3.Okay...I have used mainloop() 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 yes() is run, I know because the function is called, but what is actually happening? I mean the statement turtle.mainloop() 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 turtle.mainloop() is run.</p>

<p>So mainloop() is an infinite loop that basically blocks the execution of your code at a certain point. You call it once (and only once).  </p>

<p>so lets say:</p>

<pre><code>while true:
circle.draw()
sumden.mainloop()
print "circle is being drawn"
time.sleep(0.1)
</code></pre>

<p>You will never see the output and print statement because there is no loop.</p>

python user-interface events turtle-graphics event-loop