GUIによる項目の選択
チェックボックスとラジオボタン
いくつかある項目の中から複数または、一つだけの項目を選びたい時にはcheckBoxとradioButtonを使用する。
- checkBox
- オンとオフができるコントロール。
例えば、以下のようにするとXというラベルのついたxCheckBoxという名前のcheckBoxが作られる。
checkBox -label "X" xCheckBox;
xCheckBoxという名前のcheckBoxの現在の値は以下のコマンドで得ることができる。
checkBox -q -value xCheckBox;
オンならtrue、オフならfalseが返される。
- checkBoxGrp
- 複数のcheckBoxをまとめたもの。
- radioButton
- 複数のボタンのうち一つだけがオンになるもの。
複数のradioButtonを一組のものとしてまとめるにはradioCollectionを使用する。
どのradioButtonが選ばれているかは以下のコマンドで得ることができる。
radioButton -q -select (radioButton名);
これによってオンになっているradioButtonの名前が返される。
- radioButtonGrp
- 複数のradioButtonをまとめたもの。
radioButtonの使用例
ラジオボタンによってプリミティブ(球、キューブのうちのどれか)を作るGUIを作ってみよう。
window -title "radioButton1" window1;
columnLayout;
text -label "make Primitive";
radioCollection radioCollection1;
radioButton -label "Sphere" -select sphereButton;
radioButton -label "Cube" cubeButton;
button -label "OK"
-command "$selected = `radioCollection -q -select radioCollection1`;\
if($selected == \"sphereButton\") sphere;\
else if($selected == \"cubeButton\") nurbsCube;";
button -label "Close" -command "deleteUI window1";
showWindow;
- 2つのradioButtonはradioCollectionによって一組にまとめられてradioCollecion1という名前がついている。
- buttonの-commandで"の前に\ (バックスラッシュ)を使用しているのはコマンド文字列の区切りである"と区別するためである。
- buttonの-commandで"の中ではif文も使用できる。
練習
- 上の使用例にconeを追加せよ。
まとめ
- 複数の項目の中からいくつかを選ぶにはcheckBoxを使用する。
- 複数の項目の中から一つだけを選ぶにはradioButtonを使用する。
- radioButtonを使用するときにはradioCollectionによって一組にまとめる。
参考
Prev | Next
Home | Contents
abe@injapan.net