我对tk界面构建相对较新,并且在开始编写我需要的内容之前试图找出一些东西
在下面找到一个愚蠢的布局作为例子
我想要实现的是,当调整根窗口或(任何子窗格窗口)的大小时,内部的所有子窗口都会调整大小,同时保持50%的空间比例
在atm时,例如当我将根窗口调整到左侧时,黄色文本框会缩小,直到它完全消失(对于蓝色文本框,依此类推)
我想要的是我的两个半窗格(黄色窗格和包含黑色,蓝色和绿色窗格的窗格)在每一半上均匀显示
同样对于其他2个嵌套的窗口窗口也是如此
似乎在某个时间点,panedwindows曾经接受了一个“分数”论证,这个论点可以允许,但它似乎不再
在此先感谢您的帮助,如果我的代码太笨拙而且您想提供一个改进的代码以及我的问题的答案,那么很有必要
#!/bin/sh
#The next line executes wish - wherever it is \
exec wish "$0" "$@"
proc bindings {} {
bind . <Alt-Key-x> exit
bind . <Alt-Key-k> redraw
bind . <Key-Escape> exit
bind . <Key> { puts [focus] }
}
proc redraw {} {
# which window has focus
set foc [focus]
puts "kill and redraw focused windows $foc"
destroy $foc
if { [string equal $foc ".t1"] } {
upleftbox
.sp3 paneconfigure .t1 -before .t2
} elseif { [string equal $foc ".t2"] } {
uprightbox
.sp3 paneconfigure .t2 -after .t1
} elseif { [string equal $foc ".t3"] } {
bottombox
.sp2 paneconfigure .t3 -after .sp3
} elseif { [string equal $foc ".t4"] } {
sidebox
.sp1 paneconfigure .t4 -after .sp2
}
}
proc scrolled_text { f args } {
#----------------------------------------------
# scrolled_text from Brent Welch's book
#----------------------------------------------
frame $f
eval {text $f.text -wrap none \
-xscrollcommand [list $f.xscroll set] \
-yscrollcommand [list $f.yscroll set]} $args
scrollbar $f.xscroll -orient horizontal \
-command [list $f.text xview]
scrollbar $f.yscroll -orient vertical \
-command [list $f.text yview]
grid $f.text $f.yscroll -sticky nsew
grid $f.xscroll -sticky nsew
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f.text
}
# structure is .sp1.sp2.sp3
# defining the layout
proc sp1 {} {
panedwindow .sp1 -orient h -opaqueresize 0 -sashwidth 10
}
proc sp2 {} {
panedwindow .sp2 -orient v -opaqueresize 0 -sashwidth 10
}
proc sp3 {} {
panedwindow .sp3 -orient h -opaqueresize 0 -sashwidth 10
}
# demo textboxes to populate the 4 windows GUI
proc upleftbox {} {
text .t1 -background black -foreground lightgreen -width 18 -height 8
}
proc uprightbox {} {
text .t2 -background blue -foreground lightgreen -width 18 -height 8
}
proc bottombox {} {
text .t3 -background green -foreground lightgreen -width 18 -height 8
}
proc sidebox {} {
text .t4 -background yellow -foreground lightgreen -width 18 -height 8
}
# Main
# define basics stuff
tk_setPalette background black foreground lightgreen
wm title . paf.tk
wm minsize . 50 60
bindings
# building basic layout
# call the windows proc
sp1
sp2
sp3
sidebox
bottombox
uprightbox
upleftbox
# build the windows like russian dolls
grid .sp1 -in . -sticky nsew
.sp1 add .sp2 .t4
.sp2 add .sp3 .t3
.sp3 add .t1 .t2
# set the weight for expanding when resizing on the fly
grid columnconfigure . .sp1 -weight 1
grid rowconfigure . .sp1 -weight 1
您可以使用ttk::panedwindow
而不是panedwindow
。它的add
子命令有-weight
选项,它会根据自己的重量自动调整子窗口的大小。