0

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)
0

2 Answers 2

2

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)
Sign up to request clarification or add additional context in comments.

Comments

1

Yes, to remove an item with a tag, first you need to assign the tag with the tag option for tk.Canvas.create_xxxxx(...,tag='item1'):

self.canvas.create_image(self.getCoordinates()[0], self.getCoordinates()[1], image=ball, tag='img')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.