我想創建一個窗口,其中兩個文本框位於另一個的頂部,首先佔據25%的高度,然後佔據75%的高度。Tcl/tk - 獲取窗口高度和寬度,並在網格中設置相對文本高度
我試圖計算頂級勝利的相對高度/寬度並傳入文本命令,但沒有工作(我猜測是因爲wm幾何體返回的維度單位與傳遞給文本命令時不一樣)
以下是我的代碼:
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
,但我想用relati ve選項。如何使它工作?
解析幾何輸出時需要小心,因爲它可能在多監視器設置中具有負偏移。例如:我的「200x200 + -638 + 77」。因此'scan'語句正確地解析了[scan $ geometry'%dx%d +%d +%d「]',它能夠處理底片。 – patthoyts
感謝您的糾正,我誤解了格式的文檔。但從我目前的理解來看,前綴可能是 - 以及+,可能後面跟着數字的符號。如果是這樣,它必須由{%dx%d%* 1 [+ - ]%d%* 1 [+ - ]%d}'或正則表達式{{(\ d +)x(\ d + )[+ - ]([+ - ]?\ d +)[+ - ]([+ - ] \ d +)}'?。 –
格式WxH-X + Y(使用X偏移量的前導減號表示位置來自屏幕右端 - 請參閱tkWinWm.c中有關WM_NEGATIVE_X的註釋。因此,我們可能會得到'1x1- -2 + 3'我認爲是的,看起來像一個正則表達式是必要的 – patthoyts