选择单选按钮或缩放



我正在研究tk/tcl中的接口。

在界面中,有几个单选按钮和刻度(线性滑块(,带有显示滑块数字的条目。

您能否提供一个有关如何选择一个单选按钮或一个刻度的示例?

因此,我想将参数 -variable 和 -value 放在单选按钮和刻度上。然后,我可以使用开关{}...案例 {} ...以在选择单选按钮或比例之一时执行操作。

感谢您的帮助和榜样。

我猜是这样的事情?

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

虽然有很多方法可以做到你在问题中描述的事情,如果我理解正确的话。根据您的情况,可能会有更合适的方法来做到这一点,但是如果不看到实际的代码,很难说很多。我试图使示例尽可能简单。

最新更新