Search code examples
imagetkintertkinter-canvasself

Python Tkinter ~ canvas.delete()


How can I delete a specific image tag of a canvas with canvas.delete()? Should I put 'img' as a parameter or is something else required?

ball = PhotoImage(file='ball.png')
[Class Name and __init__]
self.canvas.delete('img')
self.canvas.create_image(self.getCoordinates()[0], self.getCoordinates()[1], image=ball)

Solution

  • Creating a canvas object returns an id. You can pass that id to the delete method.

    self.image_id = self.canvas.create_image(...)
    ...
    self.canvas.delete(self.image_id)