Advanced Search
Mail us
Home    Manuel    Links    Faq    Submit a tcl/tk Reference    Contact Us

    Some examples tcl/tk codes     Man of Bwidget     Man of blt     mkwidget screenshots     TkOgl     Video Demo real.

  Why doesn`t `.listbox curselection` or `selection get` return the proper item when I make a button binding to my listbox?
 The best way to get the selected item during a button click event on a
`listbox` is to use the following code:

bind .listbox  { set item [%W get [%W nearest %y]] }

This ensures that the item under the pointer is what will be returned as
`item`.  The reason `.listbox curselection` can fail is because the
items in `curselection` are not set until the `Listbox` class binding
triggers, which is after the instance bindings by defaults.  This is the
same reason for which `selection get` can fail, but it will also fail if
you set the `-exportselection` option to 0.