1
我正在实现一个具有以下功能的条目和按钮。点击按钮,我会得到一个检查按钮列表。选择检查按钮后,他们应该反映在条目中。以下是我的实施。我不喜欢的一件事是将条目(.e
)传递给get_values
和myok
。有没有更好的解决方案来解决我的问题?Tcl/Tk:输入按钮 - 在没有通过输入的情况下将值输入入口
entry .e -width 15 -relief sunken
button .b -text "..." -command [list get_values .e]
pack .e .b -side left
proc get_values { entry } {
toplevel .values
checkbutton .values.c1 -text "C1" -variable c1
checkbutton .values.c2 -text "C2" -variable c2
button .values.ok -text "OK" -command [list myok $entry .values]
button .values.cancel -text "Cancel" -command [list mycancel .values]
pack .values.c1 .values.c2 -side top
pack .values.cancel .values.ok -side right
}
proc myok { entry warg } {
variable c1
variable c2
$entry delete 0 end
if { $c1 } {
$entry insert insert " "
$entry insert insert "c1"
}
if { $c2 } {
$entry insert insert " "
$entry insert insert "c2"
}
destroy $warg
}
proc mycancel { warg } {
destroy $warg
}