Python Turtle - Click Events
Question: I'm currently making a program in python's Turtle Graphics. Here is my code in
case you need it

    
    
    import turtle
    turtle.ht()
    
    width = 800
    height = 800
    turtle.screensize(width, height)
    
    ##Definitions
    def text(text, size, color, pos1, pos2):
         turtle.penup()
         turtle.goto(pos1, pos2)
         turtle.color(color)
         turtle.begin_fill()
         turtle.write(text, font=('Arial', size, 'normal'))
         turtle.end_fill()
    
    ##Screen
    turtle.bgcolor('purple')
    text('This is an example', 20, 'orange', 100, 100)
    
    
    turtle.done()
    

I want to have click events. So, where the text `'This is an example'` is
wrote, I want to be able to click that and it prints something to the console
or changes the background. How do I do this?

**EDIT:**

I don't want to install anything like pygame, it has to be made in Turtle


Answer: Use the onscreenclick method to get the position then act on it in your
mainloop (to print or whatever).

    
    
    import turtle as t
    
    def main():
        t.onscreenclick(getPos)
        t.mainloop()
    main()
    

Also see : [Python 3.0 using
turtle.onclick](http://stackoverflow.com/questions/15893236/python-3-0-using-
turtle-onclick) Also see : [Turtle in python- Trying to get the turtle to move
to the mouse click position and print its
coordinates](http://stackoverflow.com/questions/17864085/turtle-in-python-
trying-to-get-the-turtle-to-move-to-the-mouse-click-position-a)

