Problem with menu "-command" option 
Author Message
 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



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Tue, 08 Oct 1996 22:57:54 GMT  
 Problem with menu "-command" option
]
] 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
]
] }
]
]
] 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

  Eventhough localVar is defined in the scope of SampleProc, memu.m
  doesn't exec the command inside the proc. So it couldn't recognize
  it. The way to do it is :

        .menu.m -command "puts stdout $localVar"

--
= Shumei Lin                  ! College of Computing

  GVU Lab: 404-894-9633       ! Atlanta, Georgia 30332-0280



Wed, 09 Oct 1996 03:42:03 GMT  
 Problem with menu "-command" option

Quote:

>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

>}

>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

     Usually when I see this error message it's because I should have used
quotes rather than use braces, try:

     "puts stdout $GLOBAL; puts stdout $LocalVar"

    I'm guessing here, but "Print" may know $GLOBAL because it is upvar'd and
is being referenced outside of your procedure.

     -- Bernie
--
+------------------------------------------------------------------------+
|   REWARD: Lost .sig, last seen in comp.sys.* or bionet.*, answers to   |

+------------------------------------------------------------------------+



Wed, 09 Oct 1996 04:04:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Options for "Inspect" command

2. ELF90 - "Unrecognized option in Command file"

3. checkbutton option "-command"

4. Help wanted: "Menu to" command

5. Problem "bad option delta" with Scrollbar

6. Problem with "null" commands

7. Problem with "-r" command line argument

8. Problems with ModelSim and "report" command

9. Beginner's Tkinter Problem "-command"

10. Problems with "file system" command

11. Newbie problem concerning the "exec"-command

12. Problem with "scan" command in tcl

 

 
Powered by phpBB® Forum Software