Hi all, cud any1 tell me how to capture the text of one line in the listbox when I select it, so that I can put it in an entry box. though there were many options given I'm unable to make it out. thanq.
When you build the listbox, set the selection:
listbox $w.hval -exportselection 1 ...
Then refer to the selected line as "curselection"
as in:
bind .open.up.hval <Double-Button-1> {
set filename [lindex $filelst [.open.up.hval curselection]]
}
I can see where Bong was going with this example, but it doesn't include quite all the code you need.
As Bong implies, the listbox curselection operation returns the index(es) of the listbox item(s) currently selected. But to then retrieve the actual text value of the item, you need to use the index as an argument to the listbox's get operation. Alternately, if you've associated a "listvariable" with a listbox, then Tk automatically keeps the contents of the listbox and the list stored in the listvariable synchronized -- which means that you could use lindex to retrieve the values from the associated listvariable rather than using the listbox get operation.
So, Bong's code just needs to add the listvariable linkage:
[tt]listbox $w.hval -listvariable filelst[/tt]
- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting,
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.