Question: I generate random figures on the screen. I want the screen to clear when I click on any circle shape. How to bind an event when a circle is clicked? I tried onclick() with clearscreen(), but it doens't work. My code: # -*- coding: utf-8 -*- import random import turtle class Figure: def __init__(self): __colors = ['red', 'green', 'yellow', 'purple', 'orange'] __figures = ['square', 'circle', 'triangle'] self.__x = random.randint(-330, 330) self.__y = random.randint(-230, 230) self.__color = random.choice(__colors) self.t = turtle.Turtle() self.t.hideturtle() self.t.fillcolor(self.__color) self.t.up() self.t.setpos(self.__x, self.__y) self.t.down() __choose = random.choice(__figures) if __choose == 'square': self.square() elif __choose == 'circle': self.circle() else: self.triangle() def square(self): self.t.begin_fill() for i in range(4): self.t.fd(50) self.t.left(90) self.t.end_fill() def circle(self): self.t.begin_fill() self.t.circle(50) self.t.end_fill() self.t.onclick(self.delete_figures) def triangle(self): self.t.begin_fill() self.t.fd(50) self.t.lt(120) self.t.fd(50) self.t.lt(120) self.t.fd(50) self.t.end_fill() def delete_figures(self, x ,y): turtle.clearscreen() turtle.tracer(1, 0) for i in range(10): Figure() turtle.mainloop()  I want the screen to clear when I click on any circle shape. How to bind an event when a circle is clicked?

Answer: onclick doesn't register a click listener on drawings the turtle has made, only on the turtle itself. But these turtles are hidden and only a few pixels large even if visible, so there's nothing to click. There are two main options:  Keep the turtle drawing the same and add a screen click listener. In the click handler, loop over all of your circles and determine if the x/y position of the click occurred within the radius of any circle. Here's an example: import random import turtle class Figure: def __init__(self): __colors = ['red', 'green', 'yellow', 'purple', 'orange'] __figures = ['square', 'circle', 'triangle'] self.__x = random.randint(-330, 330) self.__y = random.randint(-230, 230) self.__color = random.choice(__colors) self.t = turtle.Turtle() self.t.hideturtle() self.t.fillcolor(self.__color) self.t.up() self.t.setpos(self.__x, self.__y) self.t.down() self.shape = random.choice(__figures) if self.shape == 'square': self.square() elif self.shape == 'circle': self.circle() else: self.triangle() def square(self): self.t.begin_fill() for i in range(4): self.t.fd(50) self.t.left(90) self.t.end_fill() def circle(self): self.t.begin_fill() self.t.circle(50) self.t.end_fill() self.t.right(90) self.t.forward(-50) def triangle(self): self.t.begin_fill() self.t.fd(50) self.t.lt(120) self.t.fd(50) self.t.lt(120) self.t.fd(50) self.t.end_fill() def is_touching(self, x, y): return self.shape == 'circle' and self.t.distance(x, y) < 50 turtle.tracer(1, 0) figures = [] for i in range(10): figures.append(Figure()) def test_circle_click(x, y): for f in figures: if f.is_touching(x, y): turtle.clearscreen() turtle.onscreenclick(test_circle_click) turtle.mainloop()   Instead of drawing circles, use turtle.shape("circle") and turtle.color() to make the turtle look like a circle. Don't hide the turtle to allow it to be clickable using your current handler. Here's an example (and an answer in this thread from the author of that other post).