-1

I am making a program in which any amount of users can be made, and to select one, you have to click on their name, which is contained in a scrollable listbox. Is there any way (bindings or otherwise) to have a command be executed upon clicking different items in the listbox?

Me_Moo0
  • 21
  • 6

1 Answers1

0
def onselect(evt):
# Note here that Tkinter passes an event object to onselect()
w = evt.widget
index = int(w.curselection()[0])
value = w.get(index)
print 'You selected item %d: "%s"' % (index, value)

lb = Listbox(frame, name='lb')
lb.bind('<<ListboxSelect>>', onselect)

I took this in the comments of the post Getting a callback when a Tkinter Listbox selection is changed?, which contained the answer above.

Me_Moo0
  • 21
  • 6