2008年9月28日星期日

perl tk笔记: 布局管理

1:pack
pack选项
-side => 'left' | 'right' | 'top' | 'bottom
Puts the widget against the specified side of the window or Frame
widget的的方位
-fill => 'none' | 'x' | 'y'| 'both'
Causes the widget to fill the allocation rectangle in the specified direction
拉伸的方向,x轴,y轴
-expand => 1 | 0
配置rectangle是否拉伸,注意不是widget
-anchor => 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw' | 'center'
Anchors the widget inside the allocation rectangle
锚定widget的方位,上北下南左西右东
-after => $otherwidget
Puts $widget after $otherwidget in packing order
-before => $otherwidget
Puts $widget before $otherwidget in packing order
-in => $otherwindow
widget一般pack到创建它的区域中,此选项可改变widget的出现位置
Packs $widget inside of $otherwindow rather than the parent of $widget, which is the default
-ipadx => amount
直接控制widget的大小
Increases the size of the widget horizontally by amount
-ipady => amount
Increases the size of the widget vertically by amount
-padx => amount
Places padding on the left and right of the widget
边框
-pady => amount
Places padding on the top and bottom of the widget
allocation rectangle
这个是Tk中的一个概念,当一个widget,此控件占据的空间按pack的规则进行延伸填充到window边缘或者碰到其他的widget rectangles为止,这就是Allocation Rectangles
pack(-side =>left) 对应的allocation rectangles就是靠左边竖着的矩形
pack(-side =>top)顶部的矩形
这样便可以理解expand 和fill选项了

unpack一个控件
只是unpack,不是destory
$widget->packForget( );
如果重新pack的话会出现在所以pack的最后

获得控件的pack属性
@list = $widget->packInfo( );
%packinfo = $widget->packInfo;
获得控件列表
@list = $parentwidget->packSlaves( )

2:grid

grid意为格子,它的用法和html中的table非常类似

grid选项

The rest of the options are similar to those used with pack:

"-"
A special character used in the grid widget list. Increases columnspan of the prior widget in the widget list.
增加widget所占列数目
"x"
A special character used in the grid widget list. Leaves a blank space in the
grid.
标记此区域为空白
"^"
A special character used in the grid widget list. Increases rowspan of the widget in the grid directly above it.
增加widget占行数
-column => n
Sets the column to place the widget in (n >= 0).
-row => m
Sets the row to place the widget in (m >= 0).
-columnspan => n
Sets the number of columns for the widget to span beginning with -column.
-rowspan => m
Sets the number of rows for the widget to span beginning with -row.
-sticky => string
Sticks the widget to string sides. String contains characters n, s, e, or w.
向string代表的方位拉伸
-in => $otherwindow
Indicates the widget is gridded inside $otherwindow instead the parent of $widget.
-ipadx => amount
$widget b ecomes larger in x direction by amount.
-ipady => amount
$widget becomes larger in y direction by amount.
-padx => amount
Places buffer space equal to amount to the left and right of the widget.
-pady => amount
Places buffer space equal to amount on the top and bottom of the widget.
配置行和列

使用gridColumnconfigure和gridRowconfigure来配置行列参数,它们都接收行或列的序号作为第一个参数,可用选项有:-weight,-minsize,-pad,不能用grid来设置它们
%column_configs = $mw->gridColumnconfigure(0);
返回当前参数如: -minsize 0 -pad 0 -weight 0
weight:看半天没懂啥意思
只知道有一个效果:当设置为0时widget不会随窗口的resize而变化大小,设置为1就可以了。
minisize: 设置最小尺寸
pad:改变widget周围大小

获得一个cell的大小
($xoffset, $yoffset, $width, $height) = $master->gridBbox(0, 2);
删除一个widget
如pack $widget->gridForget

总行列数:
($columns, $rows) = $master->gridSize( );

所有grid子widget
@slaves = $mw->gridSlaves( );
这个方法也接收行列号作为参数返回那里的widget

没有评论: