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!

menubutton commands and labels

Status
Not open for further replies.

g6con

Technical User
Nov 4, 2005
3
US
I am adding menu buttons like this:

set mylabel "Function1"
$m add command -label $mylabel -command {

}

In the command field I need to have code that gets the label name for this button. What I mean is, in this example when I hit the button, I need code that will tell me "Function1" somehow. But I don't know how to tell Tcl to look at the current button hit and tell me its label.

I don't want to place Function1 in the command field, becuase this code will be in a loop, creating many (and a varying number of) buttons for me.

Thanks
 
why not pass the variable "mylabel" in to the command (which could be a proc)as an argument?

_________________
Bob Rashkin
 
I had thought of this before. To be more specific, I have a list that will vary every time the GUI loads based on some files in a directory... Anyway, I wanted the GUI to populate menubuttons automatically like this:

proc add_button {mylabel} {
$m add command -label $mylabel -command {
<command that uses the value stored in $mylabel>
}
}

This procedure would be called for every button. So, if I reference $mylabel in the command, it will use the last value of mylabel from when I built these buttons

Hope that made sense!
 
Right, but if you have a proc, say "bcmd {labelname} {}", then in your add_button thingy you can use quotes for immediate substitution:
[red]$m add command -label $mylabel -command "bcmd $mylabel" ...[/red]

_________________
Bob Rashkin
 
That worked. I never would have thought of that. Thanks!
 
It's been said elsewhere but probably bears repeating:

1. everything in Tcl is a string
2. "" around a string cause immediate substitution
3. {} around a string cause delayed substitution
4. [] around a string cause the string to be interpreted as a command (statement)

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top