I am trying to have the user delete rows when right clicking. I linked the button 3 pressing the event to the canvas and passed it to the next function
def eraseItem(self,event): objectToBeDeleted = self.workspace.find_closest(event.x, event.y, halo = 5) if objectToBeDeleted in self.dictID: del self.dictID[objectToBeDeleted] self.workspace.delete(objectToBeDeleted)
However, nothing happens when I right-click on a line. I tested the dictionary separately, and line objects are saved correctly.
Here is my binding:
self.workspace.bind("<Button-3>", self.eraseItem)
To query some other fragments from dictionary initialization
def __init__(self, parent): self.dictID = {} ... Some irrelevant code omitted
To create a line, I have two handlers: a click and a shutdown, which draws lines between both coordinates
def onLineClick(self, event): self.coords = (event.x, event.y) def onLineRelease(self, event): currentLine = self.workspace.create_line(self.coords[0], self.coords[1], event.x, event.y, width = 2, capstyle = ROUND) self.dictID[currentLine] = self.workspace.coords(currentLine) print(self.dictID.keys())
The dictionary prints great here. Please note that these are all functions within the same class.