Getting Turtle in Python to recognize click events
Question: I'm trying to make Connect 4 in python, but I can't figure out how to get the
coordinates of the screen click so I can use them. Right now, I want to draw
the board, then have someone click, draw a dot, then go back to the top of the
while loop, wipe the screen and try again. I've tried a couple different
options but none have seemed to work for me.

    
    
    def play_game():
    """
    When this function runs, allows the user to play a game of Connect 4
    against another person
    """
    turn = 1
    is_winner = False
    while is_winner == False:
        # Clears screen
        clear()
        # Draws empty board
        centers = draw_board()
        # Decides whose turn it is, change color appropriately
        if turn % 2 == 0:
            color = RED
        else:
            color = BLACK
        # Gets coordinates of click
        penup()
        onscreenclick(goto)
        dot(HOLE_SIZE, color)
        turn += 1
    


Answer: As well intentioned as the other answers are, I don't believe either addresses
the actual problem. You've locked out events by introducing an infinite loop
in your code:

    
    
    is_winner = False
    while is_winner == False:
    

You can't do this with turtle graphics -- you set up the event handlers and
initialization code but turn control over to the main loop event handler. My
following rework show how you might do so:

    
    
    import turtle
    
    colors = ["red", "black"]
    HOLE_SIZE = 2
    
    turn = 0
    is_winner = False
    
    def draw_board():
        pass
        return (0, 0)
    
    def dot(color):
        turtle.color(color, color)
        turtle.stamp()
    
    def goto(x, y):
        global turn, is_winner
    
        # add code to determine if we have a winner
    
        if not is_winner:
            # Clears screen
            turtle.clear()
            turtle.penup()
    
            # Draws empty board
            centers = draw_board()
    
            turtle.goto(x, y)
    
            # Decides whose turn it is, change color appropriately
            color = colors[turn % 2 == 0]
            dot(color)
    
            turn += 1
        else:
            pass
    
    def start_game():
        """
        When this function runs, sets up a new
        game of Connect 4 against another person
        """
    
        global turn, is_winner
    
        turn = 1
        is_winner = False
    
        turtle.shape("circle")
        turtle.shapesize(HOLE_SIZE)
    
        # Gets coordinates of click
        turtle.onscreenclick(goto)
    
    start_game()
    
    turtle.mainloop()
    

Run it and you'll see the desired behavior you described.

