我想制作一个主按钮,选择它时会选择其他按钮并将它们变灰。 我曾经为master中的每个按钮设置一个变量,所有这些按钮都使用-variable设置为true,但这会抛出错误,说“无效命令名1”
我的代码片段看起来像这样。
checkbutton .top.l.all -text "Select ALL" -variable "select_all" -command { [set sanity_check 1] [set verilog_check 1] [set lef_check 1] [set lib_check 1][set apl_check 1] } -font TEMP_varwidth
checkbutton .top.l.g1 -text "File name and operating conds checks" -variable "sanity_check" -command "run_file_ops"
checkbutton .top.l.g2 -text "Syntax Checks for Verilog" -variable "verilog_check" -command "run_verilog_check"
checkbutton .top.l.g3 -text "Syntax Checks for LEF" -variable "lef_check" -command "run_lef_check"
checkbutton .top.l.g4 -text "Syntax Checks for .lib" -variable "lib_check" -command "run_lib_check"
checkbutton .top.l.g5 -text "Syntax Checks for APL" -variable "apl_check" -command "run_apl_check"
grid .top.l.all -row 1 -column 2 -sticky nw
grid .top.l.g1 -row 2 -column 2 -sticky nw
grid .top.l.g2 -row 3 -column 2 -sticky nw
grid .top.l.g3 -row 4 -column 2 -sticky nw
grid .top.l.g4 -row 5 -column 2 -sticky nw
grid .top.l.g5 -row 6 -column 2 -sticky nw
答案 0 :(得分:3)
而不是复制所有按钮' "选择所有"中的逻辑按钮,只需使用invoke
命令以编程方式单击它们:
checkbutton .top.l.all -text "Select ALL" \
-variable "select_all" \
-font TEMP_varwidth \
-command select_all
proc select_all {} {
foreach w {.top.l.g1 .top.l.g2 .top.l.g3 .top.l.g4 .top.l.g5} {
$w invoke
$w configure -state disabled
}
}
这将设置按钮的状态并执行它们的命令。
答案 1 :(得分:2)
这是因为您正在评估命令两次。想象一下就是这样(因为它本质上是这样的):
checkbutton .top.l.all -text "Select ALL" -variable "select_all" -command {
[set sanity_check 1]
[set verilog_check 1]
[set lef_check 1]
[set lib_check 1]
[set apl_check 1]
} -font TEMP_varwidth
你认为这是正确的吗? set
首先计算,然后返回设置值1
。然后-command
接受'命令' {1 1 1 11}
这是发生错误的地方。正确的方法是:
checkbutton .top.l.all -text "Select ALL" -variable "select_all" -command {
set sanity_check 1
set verilog_check 1
set lef_check 1
set lib_check 1
set apl_check 1
} -font TEMP_varwidth
如果你想要它在单行上,它就变成了:
checkbutton .top.l.all -text "Select ALL" -variable "select_all" -command {set sanity_check 1; set verilog_check 1; set lef_check 1; set lib_check 1; set apl_check 1} -font TEMP_varwidth
根据评论,这是一个样本:
checkbutton .all -text "Select ALL" -variable "select_all" -command select_all -font TEMP_varwidth
proc select_all {} {
upvar sanity_check sa verilog_check v lef_check le lib_check li apl_check a select_all se
if {$se == 1} {
# First change the checkbuttons
set sa 1
set v 1
set le 1
set li 1
set a 1
# Execute their commands
run_file_ops
run_verilog_check
run_lef_check
run_lib_check
run_apl_check
# Grey them out
.g1 configure -state disabled
.g2 configure -state disabled
.g3 configure -state disabled
.g4 configure -state disabled
.g5 configure -state disabled
} else {
# Change the checkbuttons
set sa 0
set v 0
set le 0
set li 0
set a 0
# Change them back to normal
.g1 configure -state normal
.g2 configure -state normal
.g3 configure -state normal
.g4 configure -state normal
.g5 configure -state normal
}
}