1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Using Turtle graphic's onscreenclick() event but need a return value from the...

Discussão em 'Python' iniciado por Stack, Setembro 14, 2025.

  1. Stack

    Stack Membro Participativo

    I'm just some code that binds a function to my mouse click on the turtle graphics screen as such:

    import turtle
    wn = turtle.Screen()

    def token_move(x,y):
    turtle.goto(x,y)
    position = [turtle.xcor(), turtle.ycor()]
    return position

    token = turtle.Turtle()
    wn.onscreenclick(token_move)


    Now my problem is that I want the coordinates that the turtle is at after the mouse click so i can use it for the rest of my program, but because it is binded to the onscreenclick() event I can't return any value from token_move. I've tried changing the last line to:

    position = wn.onscreenclick(token_move)


    But had no luck either. Any help would be appreciated!

    Continue reading...

Compartilhe esta Página