Tcl-tk-tk-check-button-widget

提供:Dev Guides
移動先:案内検索

Tk-チェックボタンウィジェット

Tkチェックボタンは、チェックボックスの形式で複数の選択可能な項目を作成するために使用されます。 チェックボタンウィジェットの構文は以下に示されています-

checkbutton checkbuttonName options

オプション

チェックボタンウィジェットで利用可能なオプションは、次の表に以下に記載されています-

Sr.No. Syntax & Description
1

-font fontDescriptor

ウィジェットのフォントを設定するために使用されます。

2

-height number

ウィジェットの高さを設定するために使用されます。

3

-command action

ボタンのコマンドアクションを設定します。

4

-text text

ウィジェットのテキストを設定します。

5

-width number

ウィジェットの幅を設定します。

6

-variable variableName

ウィジェットの変数を設定します。

チェックボタンの簡単なTkの例を以下に示します-

#!/usr/bin/wish

grid [label .myLabel1  -text "Range 20-30 not selected" -textvariable myLabelValue1 ]
grid [checkbutton .chk1 -text "Range 20-30" -variable occupied1 -command {if {$occupied1 } {
   set myLabelValue1 {Range 20-30 selected}
} else {
   set myLabelValue1 {Range 20-30 not selected}
} }]
grid [label .myLabel2  -text "Range 30+ not selected" -textvariable myLabelValue2 ]
grid [checkbutton .chk2 -text "Range 20-30" -variable occupied2 -command {if {$occupied2 } {
   set myLabelValue2 {Range 30+ selected}
} else {
   set myLabelValue2 {Range 30+ not selected}
} }]

上記のプログラムを実行すると、次の出力が得られます-

チェックボタンの例

チェックボタン1とチェックボタン2をクリックすると、次の出力が得られます-

チェックボタンの例の選択