tcl/tk panedwindows,如何为 child windows 定义百分比大小,以便手动调整大小保持显示比例?

tcl/tk panedwindows, how to define a percentage size for child windows so that manual resizing keeps the display ratio?

我是 tk 界面构建的新手,在开始编写我需要的东西之前试图弄清楚一些东西

在下面找到一个愚蠢的布局作为示例

我想要实现的是,在调整根 window 或(任何子窗格 windows)的大小时,内部的所有子 windows 都会调整大小,同时保持 say 50 %space比率

在 atm 时,例如,当我将根 window 的大小调整到左侧时,黄色文本框会缩小直到完全消失(蓝色文本框以此类推)

我想要的是我的两个半窗格(黄色的窗格和包含黑色、蓝色和绿色的窗格)在每一半上保持均匀显示

其他 2 个嵌套面板也是如此windows 显然

似乎在某个时间点 panedwindows 曾经接受一个 "fraction" 允许的论点,但它似乎不再接受

在此先感谢您的帮助,如果我的代码太笨拙而您想要提供一个改进的代码并回答我的问题,非常感谢

#!/bin/sh
#The next line executes wish - wherever it is \
exec wish "[=12=]" "$@"

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 选项,可以根据权重自动调整大小 child windows。