Cody Bable

Generation

generate functionFri, 28 Apr 2023

create a function to store the mouse clicks and redraw from the mouse clicks in turtle.

import turtle #this is a list of lists #each sublist is a list of x,y coordinates mouseclicks = [] #create a function that stores x,y coordinates of mouse clicks def mouseclickhandler(x, y): #store x,y in a list inside the mouseclicks list mouseclicks.append([x,y]) print(mouseclicks) #create a function to draw from the mouse clicks def draw(): #go through the list of mouseclicks and draw from them #use turtle.goto(x,y) for x,y in mouseclicks: turtle.goto(x,y) #bind the mouseclick to the function mouseclickhandler turtle.onscreenclick(mouseclickhandler) #bind the turtle.onkey(draw, "space") turtle.listen() turtle.mainloop()

Questions about programming?Chat with your personal AI assistant