OptionMenuには2つの使用法があります。 まず、単にユーザの選択したオプションを必要な時に読むだけの場合には、
FFS;
w = KBMainFrame["OptionMenuEx", f, Title->"OptionMenu Example"];
v = "two";
om = OptionMenu[f,Items->{"one","two","three"},TextVariable:>v];
b = Button[f,Text->"print",Command:>Print[v]];
TkWait[];
のように、Itemsオプションで選択肢を指定します。TextVariableオプションは
必須で、選択されている項目の文字列が値として入ります。
次に、ユーザがメニューを選択する度に何らかのアクションを起したい時は、
FFS;
w = KBMainFrame["OptionMenuEx", f, Title->"OptionMenu Example"];
v = "1";
om = OptionMenu[f,TextVariable:>v];
m = Menu[om,Add->{
Button[Text->"Action 1", Command:>(v="1";Print["1"])],
Button[Text->"Action 2", Command:>(v="2";Print["2"])]}];
TkWait[];
のようにします。OptionMenuにItemsオプションを与えるかわりに、Menuを そのOptionMenuの下に作ります。この場合、OptionMenuに表示される文字列は 自動的に更新されないので、MenuのCommandで明示的に設定する必要があります。