I have a few different object tags within a tkinter canvas. I would like the user to be able to delete the current object under the mouse cursor with the tag "token"
.
I do not want all objects with the tag "token"
to be deleted, only the one under the mouse cursor. I would like any object with the tag "token"
to be able to be deleted. I want to prohibit deletion of objects with tags "line"
. I've tried:
self.canvas.delete("current")
But this allows me to delete anything under my mouse cursor (including the line object). When I tried
self.canvas.delete("token")
This allowed me to delete all items with the tag "token"
all at once. Here is an excerpt of the definitions for my line object, "token"
objects, and my delete function:
# create static line
self.canvas.create_line(50,250,200,250, width=7, fill="grey", tags="line")
#Create oval
myoval = self.canvas.create_oval(x0,y0,x1,y1, width=10, outline="black", fill="black",
tags="token")
def on_button_press_deleteoval(self,event):
'''Delete oval with double button 1 click.'''
self.canvas.delete("current")