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

Problem selecting menu option when created in a loop 1

Status
Not open for further replies.

sengkannan

Technical User
Jul 8, 2003
13
Hi I am trying to create a simple drop down menu which is created using a for loop. All the options are displayed but does not alow selection, it always picks last item on the list.
Please find short code bellow
Thanks Krish

#!/usr/bin/wish
menubutton .mb1 -text "appel" -menu .mb1.fruits
pack .mb1 -side left -fill y
set fruits(1) "appel"
set fruits(2) "pear"
set fruits(3) "orange"
set fruits(4) "grapes"
set fruits(5) "plums"
set m [menu .mb1.fruits -tearoff 0]
for {set i 1} {$i < 5} {incr i} {
$m add command -label $fruits($i) -command {.mb1 configure -text "$fruits($i)"}
}
 
OK. The problem is the curly braces, {}, in your "-command" setting. The variable substitution is delayed until the command is executed, when i=5 and the value is "plums".
Instead of -command {.mb1 configure -text "$fruits($i)"}, you should use: -command ".mb1 configure -text $fruits($i)".
[note that $fruits($i) does not need quotes at all]
By the way "appel" should be "apple".

Bob Rashkin
rrashkin@csc.com
 
Thanks for your speedy response its working corectly now.
It seems I need to brush up on my speeling and TCL/TK fundementals
Thnaks again Krish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top