Centrum123 Centrum123 - 1 month ago 8
Python Question

My turtle program in python acts like it has been clicked

import turtle

window = turtle.Screen()

pen = turtle.Turtle()

def star():

pen.forward(100);

turtle.onscreenclick(star())

window.mainloop()


I am very new to turtle,and python itself, I am just using some of the documentation that I found on the python website, but when I run this program it runs my function star without the screen even being clicked. The end goal of this program would be for me to click then it would run the function, then if I clicked again the screen would clear and the function would be run again.
Thanks for the help!

Answer

You need to pass reference to start function into onscreenclick, and make start to accept two arguments:

def star(x,y):

    pen.forward(100);

turtle.onscreenclick(star)
Comments