Tcl-tk-tk-selection-widgets

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

Tk-選択ウィジェット

選択ウィジェットは、Tkアプリケーションのさまざまなオプションを選択するために使用されます。 利用可能な選択ウィジェットのリストは次のとおりです。

Sr.No. Widgets & Description
1

Radiobutton

オン/オフボタンとラベルのセットがあり、そのうちの1つを選択できるウィジェット。

2

Checkbutton

オン/オフボタンとラベルのセットがあり、その多くを選択できるウィジェット。

3

Menu

メニュー項目のホルダーとして機能するウィジェット。

4

Listbox

1つ以上のセルを選択できるセルのリストを表示するウィジェット。

選択ウィジェットを使用して、単純なTkの例を以下に示します-

#!/usr/bin/wish

grid [frame .gender ]
grid [label .label1  -text "Male" -textvariable myLabel1 ]
grid [radiobutton .gender.maleBtn -text "Male"   -variable gender -value "Male"
   -command "set  myLabel1 Male"] -row 1 -column 2
grid [radiobutton .gender.femaleBtn -text "Female" -variable gender -value "Female"
   -command "set  myLabel1 Female"] -row 1 -column 3
.gender.maleBtn select
grid [label .myLabel2  -text "Range 1 not selected" -textvariable myLabelValue2 ]
grid [checkbutton .chk1 -text "Range 1" -variable occupied1 -command {if {$occupied1 } {
   set myLabelValue2 {Range 1 selected}
} else {
   set myLabelValue2 {Range 1 not selected}
} }]
proc setLabel {text} {
   .label configure -text $text
}

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

選択ウィジェットの例