Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox

Status
Not open for further replies.

RajVerma

Programmer
Jun 11, 2003
62
DE
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]]
}

Bob Rashkin
rrashkin@csc.com
 
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 &quot;listvariable&quot; 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, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top