选择单选按钮或比例
choose either radiobutton or scale
我正在 tk/tcl 中的界面上工作。
在界面中,有几个单选按钮和刻度(线性滑块),带有用于显示滑块编号的条目。
能否请您举例说明如何 select 一个单选按钮或一个比例尺?
因此,我想将参数 -variable 和 -value 添加到单选按钮和标度。然后,我可以使用 switch {} ...Case {} ... 在单选按钮或比例之一被 selected 时执行操作。
感谢您的帮助和示例。
我猜是这样的吧?
package require Tk
set radios [list .r1 .r2 .r3]
set scales [list .s1 .s2 .s3]
lassign {0 0 0} r1 r2 r3
radiobutton .r1 -text "radio1" -command {freeze radio .r1} -variable r1
radiobutton .r2 -text "radio2" -command {freeze radio .r2} -variable r2
radiobutton .r3 -text "radio3" -command {freeze radio .r3} -variable r3
scale .s1 -orient horizontal -length 200 -from 0 -to 100 -command {freeze scale .s1} \
-tickinterval 20
scale .s2 -orient horizontal -length 200 -from 0 -to 100 -command {freeze scale .s2} \
-tickinterval 20
scale .s3 -orient horizontal -length 200 -from 0 -to 100 -command {freeze scale .s3} \
-tickinterval 20
# Disables all the other widgets of the same 'type' except the one touched
proc freeze {type w args} {
switch $type {
radio {
upvar radios radios
foreach n $radios {
if {$n != $w} {
$n configure -state disabled
}
}
}
scale {
upvar scales scales
foreach n $scales {
if {$n != $w} {
$n configure -state disabled
}
}
}
}
}
pack {*}$radios {*}$scales
虽然有很多方法可以完成您在问题中描述的内容,但如果我理解正确的话。根据您的情况,可能有更合适的方法来执行此操作,但如果没有看到实际代码就很难说这么多。我尽量使示例尽可能简单。
我正在 tk/tcl 中的界面上工作。
在界面中,有几个单选按钮和刻度(线性滑块),带有用于显示滑块编号的条目。
能否请您举例说明如何 select 一个单选按钮或一个比例尺?
因此,我想将参数 -variable 和 -value 添加到单选按钮和标度。然后,我可以使用 switch {} ...Case {} ... 在单选按钮或比例之一被 selected 时执行操作。
感谢您的帮助和示例。
我猜是这样的吧?
package require Tk
set radios [list .r1 .r2 .r3]
set scales [list .s1 .s2 .s3]
lassign {0 0 0} r1 r2 r3
radiobutton .r1 -text "radio1" -command {freeze radio .r1} -variable r1
radiobutton .r2 -text "radio2" -command {freeze radio .r2} -variable r2
radiobutton .r3 -text "radio3" -command {freeze radio .r3} -variable r3
scale .s1 -orient horizontal -length 200 -from 0 -to 100 -command {freeze scale .s1} \
-tickinterval 20
scale .s2 -orient horizontal -length 200 -from 0 -to 100 -command {freeze scale .s2} \
-tickinterval 20
scale .s3 -orient horizontal -length 200 -from 0 -to 100 -command {freeze scale .s3} \
-tickinterval 20
# Disables all the other widgets of the same 'type' except the one touched
proc freeze {type w args} {
switch $type {
radio {
upvar radios radios
foreach n $radios {
if {$n != $w} {
$n configure -state disabled
}
}
}
scale {
upvar scales scales
foreach n $scales {
if {$n != $w} {
$n configure -state disabled
}
}
}
}
}
pack {*}$radios {*}$scales
虽然有很多方法可以完成您在问题中描述的内容,但如果我理解正确的话。根据您的情况,可能有更合适的方法来执行此操作,但如果没有看到实际代码就很难说这么多。我尽量使示例尽可能简单。