title: How can I return the index of a tkinter Listbox selection back to the function where the bind was called?
body: <p>I'm trying to write a program that returns the index of a selected Listbox item to the function where the bind function was called.</p>
  <p>The below program simply prints the index of the selected item inside the get_index function once the item is clicked; however, I want the index to be returned to the main function rather than being contained in the get_index function. Is what I'm trying to accomplish even possible?</p>
  <pre><code>import tkinter as tk
  
  def get_index(event):
      selection = event.widget.curselection()
      if selection:
          index = selection[0]
          print(index)    # Want to return here instead of print
      else:
          pass
  
  def main():
      root = tk.Tk()
      root.geometry(&quot;300x150&quot;)
  
      my_list = tk.Listbox(root)
      my_list.pack(pady=15)
  
      options = [
          &quot;Monday&quot;,
          &quot;Tuesday&quot;,
          &quot;Wednesday&quot;,
          &quot;Thursday&quot;,
      ]
  
      for option in options:
          my_list.insert(&quot;end&quot;, option)
  
      my_list.bind(&quot;&lt;&lt;ListboxSelect&gt;&gt;&quot;, get_index)
  
      root.mainloop()
  
  if __name__ == &quot;__main__&quot;:
      main()
  </code></pre>