Trying to draw circle when I click screen but draws before I click because coordinates defined as variables
06:43 23 Dec 2021

In Python turtle, I'm trying to print a circle when I click the screen, but it prints before I even click because the x,y coordinates are defined as variables.

I was trying to make tic tac toe and so far it makes the lines and when I click in a space I get my x, y coordinates. If they are within a range, they print a circle in that particular coordinate. It works well execpt for the middle square which prints without me clicking, right after I run the program.

The program I'm using to get coordinates is this:

xclick = 0
yclick = 0

def getcoordinates():
    screen.onscreenclick(modifyglobalvariables)


def modifyglobalvariables(rawx, rawy):
    global xclick
    global yclick
    xclick = int(rawx//1)
    yclick = int(rawy//1)

getcoordinates()

Here the starting value of xclick and yclick is 0, 0 so that's the problem. Is there a way to get around this? Where I don't need to initialise x, y as 0?

python turtle-graphics python-turtle