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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tk Listbox?

Status
Not open for further replies.

zackiv31

Programmer
May 25, 2006
148
US
I want to have a Listbox that I am able to scroll, allowing the user to only select one value, and whenever a value is selected I want to run a command.

Listbox does not contain a "command" parameter, so I need something else... Optionmenu doesn't work because my list is larger then the height of the screen.

Any suggestions on what to use instead appreciated.
 
Any time the selection changes in the listbox, the virtual event <<ListboxSelect>> will be generated. It is easiest to bind to this event to be made aware of any changes to listbox selection.

I suggest you set up your own binding using the aforementioned event and the selection itself:
pathName curselection
Returns a list containing the numerical indices of all of the elements in the listbox that are currently selected. If there are no elements selected in the listbox then an empty string is returned.

_________________
Bob Rashkin
 
I'm new to binding... can u give me an example of how to bind it to call an op?
 
Let's say you specify your listbox .frame1.lb1 and attach it to a list lst1:
Code:
pack [listbox .frame1.lb1 -listvariable lst1] -side top

Now you want to bind the event to a proc lstEvnt
Code:
bind .frame1.lb1 <<ListboxSelect>> {lstEvnt .frame1.lb1 $lst1}
passing the name of the widget and the list to the proc

Now, in your proc you want to identify the selection:
Code:
proc lstEvnt {wndw lst} {
  set indx [$wndw curselection]
  set slctn [lindex $lst $indx]
}

Now, albeit in this case only inside your proc, the variable slctn contains the item selected from the list.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top