Ask coding questions

← Back to all posts
Python Turtle onkeypress() and onkeyrelease()
Four_Of_Clubs (88)

I don't know much about Python or coding in general, so this could just be some ignorance on my part. Disclaimer out of the way, I cant seem to use the functions above. I just get an error saying it has no attribute 'onkeypress()'. Is it not supported or something? Is this normal? Am I just a complete moron and forgot to put some crucial line for setup? Please let me know, Thanks.

Commentshotnewtop
YuAndy (14)

Try this:
screen=turtle.Screen() create screen turtle
turtle.setheading(90)
def up(): create function for onkey
turtle.forward(40)
while True:
screen.onkey(up,"Up") screen.onkey(function,key)