Tk Listbox - Selected Item ?

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Thu Apr 14 09:20:41 EDT 2005


Peter Moscatt wrote:
> I am having trouble understanding the methods for the Listbox from Tk.
> 
> If I was to select at item in the list using a mouse click (have already
> created the bind event) - what method returns the text of the selected
> item ?
> 
> Pete
> 


Pete,

pydoc Tkinter.Listbox

<snip>

  |  curselection(self)
  |      Return list of indices of currently selected item.
  |
  |  delete(self, first, last=None)
  |      Delete items from FIRST to LAST (not included).
  |
  |  get(self, first, last=None)
  |      Get list of items from FIRST to LAST (not included).

So to get the value of the selected item:

lb.get(lb.curselection()[0])


provided the listbox is in single selection mode or only one item is
selected

Martin





More information about the Python-list mailing list