[Tutor] how can I exit a while loop in turtle graphics

Peter Otten __peter__ at web.de
Tue Feb 11 11:41:31 CET 2014


Ian D wrote:

> I am trying to exit a while loop whilst using turtle graphics.
> I don't seem to have the logic correct at all.
> I have tried a few different things
> 
> These might seem a bit illogical to you guys but to me they make some
> sense, sadly
> 
> I just don't really grasp these while loops and their usage.(obviously)
> 
> I am trying to find a way to use a while loop with the turtle graphics

The following seems to work:

import turtle

def quit():
    global more
    more = False

turtle.onkey(quit, "Up")
turtle.listen()

more = True
while more:
    turtle.left(100)
    turtle.forward(300)




More information about the Tutor mailing list