Tk复选框用于创建复选框形式的多个可选项目。选中按钮小部件的语法如下所示-
checkbutton checkbuttonName options
下表中列出了可用于检查按钮窗口小部件的选项-
Sr.No. | Syntax & Remark |
---|---|
1 | -font fontDescriptor 用于设置小部件的字体。 |
2 | height number 用于设置小部件的高度。 |
3 | -command action 设置按钮的command action。 |
4 | -text text 链接:https://www.learnfk.comhttps://www.learnfk.com/tcl-tk/tk-check-button-widget.html 来源:LearnFk无涯教程网 设置小部件的文本。 |
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} } }]
当无涯教程运行上面的程序时,将获得以下输出-
当单击check button1和check button2时,将获得以下输出-
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)