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。

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 Button Example

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

Check Button Example Selected

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

技术教程推荐

从0开始学游戏开发 -〔蔡能〕

如何看懂一幅画 -〔罗桂霞〕

To B市场品牌实战课 -〔曹林〕

动态规划面试宝典 -〔卢誉声〕

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

说透区块链 -〔自游〕

编程高手必学的内存知识 -〔海纳〕

网络排查案例课 -〔杨胜辉〕

遗留系统现代化实战 -〔姚琪琳〕

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