How to get widget name in event?
<pre><code>from tkinter import *

main = Tk()

def flipper(event):
    # I'd like to do this:
    #if widgetname == switcher:
        #do stuff
    #if widgetname == switcher1:
        #do stuff
    return

switcher = Label(main, bg='white', text=&quot;click here&quot;, font=&quot;-weight bold&quot;)
switcher.grid()
switcher.bind(&quot;&lt;Button-1&gt;&quot;, flipper)


switcher1 = Label(main, bg='white', text=&quot;click here&quot;, font=&quot;-weight bold&quot;)
switcher1.grid()
switcher1.bind(&quot;&lt;Button-1&gt;&quot;, flipper)

switcher2 = Label(main, bg='white', text=&quot;click here&quot;, font=&quot;-weight bold&quot;)
switcher2.grid()
switcher2.bind(&quot;&lt;Button-1&gt;&quot;, flipper)

switcher3 = Label(main, bg='white', text=&quot;click here&quot;, font=&quot;-weight bold&quot;)
switcher3.grid()
switcher3.bind(&quot;&lt;Button-1&gt;&quot;, flipper)

switcher4 = Label(main, bg='white', text=&quot;click here&quot;, font=&quot;-weight bold&quot;)
switcher4.grid()
switcher4.bind(&quot;&lt;Button-1&gt;&quot;, flipper)

switcher5 = Label(main, bg='white', text=&quot;click here&quot;, font=&quot;-weight bold&quot;)
switcher5.grid()
switcher5.bind(&quot;&lt;Button-1&gt;&quot;, flipper)


main.mainloop()
</code></pre>
<p>In my event function I'd like to do different things based on the label that is clicked. What im stumped on is that I can only get the identifier number of the widget that is clicked, not the name. If I could get the identifier of all my widgets then I could do:</p>
<pre><code>def flipper(event):
    if event.widget == switcher.identifier():
           do stuff
</code></pre>
<p>but I can't find how to get the id of a specified widget either...</p>
<p>How can I get the name of a widget by its identifier (<code>event.widget()</code>)?</p>
<p><strong>Or</strong> how can I get the identifier of a specified widget name?</p>
<p>If neither are possible, then I'd have to make a different function and bind for each label which is a lot of work that hopefully is not necessary.</p>
<hr />
<p>Edit:</p>
<pre><code>from tkinter import *

main = Tk()

def flipper(event, switch):
    if switch.widget == 's1':
        print(&quot;got it&quot;)

switcher = Label(main, bg='white', text=&quot;click here&quot;, font=&quot;-weight bold&quot;)
switcher.grid()
switcher.bind(&quot;&lt;Button-1&gt;&quot;, flipper)
switcher.widget = 's1'


main.mainloop()
</code></pre>