PDA

View Full Version : Getting button names


westiemad
08-13-2005, 02:12 PM
Hi guys, I think I might have gone past the solution to this.


proc UI()
{
window -width 150;
columnLayout -adjustableColumn true;
string $names[] = {"Jeff","John","Paul","Keith"};
for($i=0;$i<4;$i++)
{
button -label $names[$i];
}
showWindow;
}
UI;


ok not a blistering piece of code, but its a simpliefied version. Ok, I want to get the label of the button thats been pressed. 2 things to note, firstly its inside a loop, secondly the whole lot is inside a procedure. Use any method you want, accept removing the loop or the procedure (for the time being). Feel free to add anything to the code you wish. You can add commands to the button, another procedure called by the button, variables etc etc

westiemad
08-13-2005, 06:46 PM
SOLVED (Hopefully)

GennadiyKorol
08-13-2005, 11:26 PM
Well, not sure I understood the assignment correctly:), but something like this should work:


proc UI()
{
window -width 150;
columnLayout -adjustableColumn true;
string $names[] = {"Jeff","John","Paul","Keith"};

string $Cmd;
for($i=0;$i<4;$i++)
{
$Cmd = "button -label "+"\""+$names[$i]+"\""+" -c \"ReturnLabel(\\\""+$names[$i]+"\\\");\"";
eval( $Cmd );
}
showWindow;
}
UI;

proc ReturnLabel( string $lbl)
{
print $lbl;
};

westiemad
08-14-2005, 11:28 AM
thanks mr hawk, this was different to how I did it, I can't seem to get 2 arguements passed into the procedure tho.

GennadiyKorol
08-14-2005, 11:55 AM
Just adding another variable to the proc for it to print 2 names, the current, and the name of the next button. Should work:

proc UI()
{
window -width 150;
columnLayout -adjustableColumn true;
string $names[] = {"Jeff","John","Paul","Keith"};

string $Cmd;
for($i=0;$i<4;$i++)
{
$Cmd = "button -label "+"\""+$names[$i]+"\""+" -c \"ReturnLabel(\\\""+$names[$i]+"\\\",\\\""+$names[$i+1]+"\\\");\"";
eval( $Cmd );
}
showWindow;
}
UI;

proc ReturnLabel( string $lbl1, string $lbl2 )
{
print $lbl1; print $lbl2;
}

CGTalk Moderation
08-14-2005, 11:55 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.