Skip to content
Sign upLog in
← Back to Community
mouse&keyboard events
Profile icon
YanivGofman

how the heck i am suppesd to do mouse and keyboard events?
someone pls help its for a test

Voters
Profile icon
AndrewLiu47
Profile icon
YanivGofman
Comments
hotnewtop
Profile icon
LeonDoesCode

Key Events

You can do key events in turtle by doing screen.onkey(callback, key). Switch out the callback for the function you want to do when the key is pressed (without the ()), and the key to a string that represents the key you want to get the event for.

E.g

def up(): # Do stuff screen.onkey(up, "Up")

Mouse Events

You can do mouse events in turtle by doing screen.onclick(callback). Similarly to the key events, the callback will be the function to call when the screen is clicked (without the ()). You will get an x and y coordinate when the function is called, so make sure you allow those arguments to be parsed in.

E.g

def click(x, y): # Do stuff screen.onclick(click)

Note: Make sure to add turtle.listen() before your events to be able to use them.

Profile icon
AllAwesome497

Please provide more context to this question, we don't know exactly what you are asking what to do.