【发布时间】:2016-07-08 04:39:32
【问题描述】:
我想创建一个窗口,其中包含两个文本框,一个在另一个之上,第一个占据 25% 的高度,下一个占据 75% 的高度。
我试图计算顶层 win 的相对高度/宽度并传递给 text 命令但没有用(我猜是因为 wm 几何返回的尺寸单位与传递给 text 命令时的尺寸单位不同)
以下是我的代码:
toplevel .t
wm geometry .t 1500x800+10+10
update
proc topAspect {args} {
regexp {(\d+)} $args -> relAspect
regexp {([^\d|%]+)} $args -> aspect
regexp {(.*)x(.*)[+-](.*)[+-](.*)} [wm geometry .t] -> width height x y
puts "width->$width height->$height x->$x y->$y"
switch -regexp [string tolower $aspect] {
x {
return [expr $x + $relAspect]
}
y {
return [expr $y + $relAspect]
}
w {
return [expr $width * $relAspect / 100]
}
h {
return [expr $height * $relAspect / 100]
}
default {
log::log error "Unsupported relative aspect $aspect cannot be determined for top level window"
}
}
}
text .t.text1 -height [topAspect -width 25%] -width [topAspect -width 99%]
grid .t.text1 -sticky news
text .t.text2 -height [topAspect -width 75%] -width [topAspect -width 99%]
grid .t.text2 -sticky news
当我尝试跟随时 - 它确实给了我一些不错的 GUI:
text .t.text1 -height 20 -width [topAspect -width 99%]
grid .t.text1 -sticky news
text .t.text2 -height 20 -width [topAspect -width 99%]
grid .t.text2 -sticky news
但我想使用相对选项。如何让它发挥作用?
【问题讨论】: