Tk 中的 Checkbutton部件函数

首页 / Tcl/Tk入门教程 / Tk 中的 Checkbutton部件函数

Tk复选框用于创建复选框形式的多个可选项目。选中按钮小部件的语法如下所示-

checkbutton checkbuttonName options

Checkbutton - 参数

下表中列出了可用于检查按钮窗口小部件的选项-

Sr.No.Syntax & Remark
1

-font fontDescriptor

用于设置小部件的字体。

2

height number

用于设置小部件的高度。

3

-command action

设置按钮的command action。

链接:https://www.learnfk.comhttps://www.learnfk.com/tcl-tk/tk-check-button-widget.html

来源:LearnFk无涯教程网

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}
} }]

当无涯教程运行上面的程序时,将获得以下输出-

Check Button Example

当单击check button1和check button2时,将获得以下输出-

Check Button Example Selected

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Java核心技术面试精讲 -〔杨晓峰〕

邱岳的产品实战 -〔邱岳〕

Web协议详解与抓包实战 -〔陶辉〕

手机摄影 -〔@随你们去〕

容器实战高手课 -〔李程远〕

体验设计案例课 -〔炒炒〕

超级访谈:对话张雪峰 -〔张雪峰〕

计算机基础实战课 -〔彭东〕

Dubbo源码剖析与实战 -〔何辉〕

好记忆不如烂笔头。留下您的足迹吧 :)