Tcl/Tk:当用户改变窗口大小时如何缩放小部件 [英] Tcl/Tk: How to scale the widgets when the user changes the size of the window

查看:28
本文介绍了Tcl/Tk:当用户改变窗口大小时如何缩放小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口,里面有小部件.当我手动重新调整窗口大小时,小部件会在高度减小时自行缩放,但在宽度更改或高度扩大到初始高度之外时不会.如何使小部件堆叠到窗口的边框?

I have a window with widgets inside it. When I re-size the window manually, the widgets will scale them self when the height is reduced, but not when the width is changed or when the height is enlarged beyond the initial height. How do I make the widgets to be stack to the borders of the window?

创建窗口的代码:

wm title $base "KitKite Sparam Viewer"
set frm_main      [frame  $base.main_frm]
pack $frm_main

grid [frame $frm_main.graph ] -row 1 -column 1
set g [sparam_graph_widget $frm_main.graph graph]

grid [set frm [frame $frm_main.frm]] -row 1 -column 2
#from and to frame
set from      [frame $frm.from -relief ridge -bd 2]
set from_lbl  [label $from.lbl -text "From:"]
set f_tbl_frm [frame $from.tbl_f]
set to        [frame $frm.to -relief ridge   -bd 2]
set to_lbl    [label $to.lbl   -text "To:"]
set t_tbl_frm [frame $to.tbl_t]

grid $from      -column 1 -row 1 -sticky nwe
grid $from_lbl  -row 1 -sticky nsew
grid $f_tbl_frm -row 2 -sticky nsew
grid $to        -column 2 -row 1 -sticky nwe
grid $to_lbl    -row 1 -sticky nsew
grid $t_tbl_frm -row 2 -sticky nsew

set from_t [sparam_table_widget $f_tbl_frm f_tbl]
set to_t   [sparam_table_widget $t_tbl_frm t_tbl]

set data        [frame $frm.data]
set data_lbl    [label $data.lbl -text "Choose data type to show"]
set isi         [checkbutton $data.cb_isi -variable cb(isi) -command [list __sp_data_changed isi $g] -text ISI       ]
set xt          [checkbutton $data.cb_xt  -variable cb(xt)  -command [list __sp_data_changed xt  $g] -text XT        ]
set ref         [checkbutton $data.cb_ref -variable cb(ref) -command [list __sp_data_changed ref $g] -text Reflection]
set conf_button [button $data.bt_conf -text "Configure connections" -command [list __sp_configure_datapath]]

grid $data        -column 1 -row 2 -columnspan 2 -sticky new
grid $data_lbl    -column 1 -row 1 -columnspan 2 -sticky nsew
grid $isi         -column 1 -row 2               -sticky nsw
grid $xt          -column 1 -row 3               -sticky nsw
grid $ref         -column 1 -row 4               -sticky nsw
grid $conf_button -column 2 -row 2 -rowspan 3    -sticky nsew

grid rowconfigure $frm 1 -weight 4 -uniform 1
grid rowconfigure $frm 2 -weight 1 -uniform 1
grid rowconfigure $frm_main 1 -weight 5 -uniform 1

$base 是使用 toplevel 创建的窗口的名称sparam_graph_widgetsparam_table_widget 是创建并放置在框架内的过程,它们为它们提供了图形和表格的自定义小部件(相应地)

$base is the name of the window created using toplevel sparam_graph_widget and sparam_table_widget are procedures that create and place inside the frame given to them custom widgets of a graph and a table (accordingly)

推荐答案

为了让至少一个小部件扩展以消耗空间,您需要设置至少一列的权重为非零.

In order for at least one widget to expand to consume the space, you need to set at least one column to have a non-zero weight.

grid columnconfigure $containerWidget $someWidgetOrIndex -weight 1

请注意,一旦您这样做,该列将优先处理水平方向上的所有大小变化.您可以通过将多个列设置为非零权重来调整这一点,并为不同的列赋予不同的权重(-weight 2 将收到两倍于 -weight 1 的变化).

Note that once you do that, that column preferentially deals with all the size changes in the horizontal direction. You can adjust this by setting multiple columns to have non-zero weights, and give different columns different weights (-weight 2 will receive twice as large changes as -weight 1).

您可能还需要调整用于pack 外框的选项.通过将不同的帧设置为不同的颜色来进行调试,这样您就可以看到发生了什么......

You might also need to adjust the options used to pack the outer frame. Debug by setting different frames to different colors so you can see what's going on…

这篇关于Tcl/Tk:当用户改变窗口大小时如何缩放小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆