import turtle
def f():
    turtle.forward(10)
def l():
    turtle.left(1)
def r():
    turtle.right(1)
def b():
    turtle.back(5)
turtle.onkey(f,"Up")
turtle.onkey(l,"Left")
turtle.onkey(r,"Right")
turtle.onkey(b,"Down")
turtle.showturtle()
turtle.listen()
while True:
    print,

EDIT: add turtle.showturtle() but STILL doesn't work

Edited 3 Years Ago by james.lu.75491856

How does it not work? Are you getting a syntax error on the funny print line? What is that line supposed to accomplish? That's not a valid use of print.

Anyway using an empty infinite loop to prevent the turtle window from closing is a very bad idea (it will cause the Python process to cause 100% CPU usage) and won't work properly anyway. You should simply call turtle.mainloop().

Edited 3 Years Ago by sepp2k

import turtle
def circle():
    turtle.left(1)
    turtle.forward(2)
def f():
    print"F"
    turtle.forward(10)
def l():
    print"L"
    turtle.left(15)
def r():
    print"R"
    turtle.right(15)
def b():
    print"B"
    turtle.back(5)
def red():
    turtle.pencolor("red")
    print "Changed color to red"
def blue():
    turtle.pencolor("blue")
    print "Changed color to blue"
def green():
    turtle.pencolor("green")
    print "Changed color to green"
turtle.onkey(f,"Up")
turtle.onkey(l,"Left")
turtle.onkey(r,"Right")
turtle.onkey(b,"Down")
turtle.onkey(red,"r")
turtle.onkey(blue,"b")
turtle.onkey(green,"g")
#turtle.ondrag(turtle.goto)
turtle.shape("turtle")
circle()
#mode("world")
turtle.listen()
turtle.showturtle()
turtle.mainloop()

NOW it works.
I just needed to print something....

This question has already been answered. Start a new discussion instead.