Python 3.0 using turtle.onclick

前端 未结 6 1754
梦毁少年i
梦毁少年i 2020-12-04 03:51

So here is my problem, I have to make a picture for my CS class and it is really frustrating estimating in turtle. I planed to use .onclick() to show me to position.

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 04:03

    You have to get first the screen object the turtle is drawing on and then call onclick() of the screen object. Here is an example:

    import turtle as t
    
    def getPos(x,y):
        print("(", x, "," ,y,")")
        return
    
    def main():
        s = t.getscreen()
        s.onclick(getPos)
        t.mainloop()
    
    main()
    

提交回复
热议问题