tk_optionMenu usage

From: Aleksandar Vujevic (vuje_at_ifg.uni-hannover.de)
Date: 02/26/04


Date: Thu, 26 Feb 2004 09:45:49 +0100

Hi everbody,

I want to use a tk_optionMenu and show some widegts or remove them
depending on the value of the menu.
I am having trouble finding the right way to do it. The example below
works but I would rather not use a private (?) tk proc. It's not
compatible with tcl 8.3 where tk is not yet moved in its own namespace.
tk_menuInvoke would be the call there.

Is there a better way of achieving this behaviour?

Greetings,
Aleks

Example (tcl/tk 8.4.5):

toplevel .t
tk_optionMenu .t.o var 1 2
label .t.l -text "label"

bind .t.o.menu <ButtonRelease> toggle

grid .t.o
grid .t.l
grid remove .t.l

proc toggle {} {

   tk::MenuInvoke .t.o.menu 1
   global var
   if { $var == 1 } {
     grid .t.l
   } else {
     grid remove .t.l
   }
}


Quantcast