In Tkinter, I have a multiple widgets bound to the left-mouse button. They all trigger the same event when clicked.
How do I recover which widget was clicked?
I want it so when say Label2
was pressed, I'd be able to recover that Label2
was the widget that was pressed within the event it triggered.
For those trying to identify an item on a canvas that was clicked, one must first use this technique to get the canvas itself, and then ask the canvas which item was clicked. Things drawn on a canvas aren't widgets, so they can't be checked "directly". See When a rectangle on a canvas is clicked, how can I get the ID of that rectangle? for details.
def f(event):
caller = event.widget