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!

Bind label and listbox

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I would like to bind a label and a listbox i.e I want to update the label text to the element I select in the listbox.

I have got the following in the main prog
global labelp
label .project.label -text "$labelp"

in the listbox function I have
bind $w.frame.list <Double-1> {
global labelp
set labelp [selection get]
}

It does not update the main prog label even if the var is global, do I need to &quot;redraw the label&quot;? and how do I do this?

thanks!
 
Unfortunatly the label widget does not have the -textvariable option that the entry widget has.
This option ties a variable and a widget in such a way that all modification of the variable updates the widget.

But it is easy to do the same thing with [trace variable]:
Code:
trace variable update ::labelp w update_label
proc update_label {args} { .project.label config -text $::labelp }

Each time the global variable labelp is written, the update_label proc is called and the label widget is updated :):labelp is a shortland to the global variable labelp).

Good luck!

ulis
 
Ok thanks Ulis but where can I put thoses lines? in the main prog? I have just tried and I got Error startup script
wrong #args should be trace variable name ops command.

Thanks
 
I have just tried label xxx -textvariable label and now it updates fine...

label has a textvariable option!

 
OOps! I made a mistake in [trace variable].
You should modify your main prog:
Code:
label .project.label -text $::labelp
trace variable ::labelp w update_label
proc update_label {args} { .project.label config -text $::labelp }
Good luck!

ulis
 
Cool!
So you only need to add
Code:
-textvariable ::labelp
to the text definition.

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top