
Problem with menu "-command" option
I recently ran into a little problem with the -command option
for a menu element. The code resembles something like this:
proc SampleProc {} {
upvar GLOBAL_VAR GLOBAL
set LocalVar "hello"
menubutton .menu -text "File" -menu .menu.m
menu .menu.m
.menu.m add command -label "Print" -command {puts stdout $GLOBAL; \
puts stdout $LocalVar}
pack .menu
Quote:
}
Now the Print option knows exactly what the value of the GLOBAL variable is.
But it chokes on LocalVar -- it gives me an "Error: Can't read "LocalVar": no
such variable" message. It would appear that the menubar options are totally
oblivious to the existance of any local variables defined in the same procedure
as them. Am I doing anything wrong? Does anyone know the reason or a solution.
[Please note that I do not intend to ultimately have the "puts" commands as the
commmand line to be executed by this menubutton: I would like to call another
proc, but that proc must also know the value of LocalVar. Hence the puts
commands for program tracing purposes.]
Thanks,
Jody
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jody McDonnell, esq.
Bell-Northern Research
Ottawa, Ontario
Dept. 7Z35, SOS Based Tools and Realtime Performance
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~