Packing Space is the area the packer allows for the placement of the widget.
填充区域是填充器允许放置部件的区域。
Display Space is the area requested by a widget for the purposes of painting itself.
显示区域是填充器部件要求的用来描绘其本身的区域。
-fill 选项能让部件充满分配的填充区域,显示区域也一样。
eg:
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
-ipadx 和 -ipady 也可以让部件获得更多的填充区域。
-padx 和 -pady 可以分配由部件覆盖的填充区域。
通过分析暴露在外面的button部件的数据结构,可以知道在button部件中记录了padx与pady,height与widget。而并没有ipadx与ipady。所以我们通过更改button部件的相应参数来改变部件的显示状态。
eg1:
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
eg2:
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
eg1 与 eg2 的区别是,eg1在定义button部件时,设置参数padx为2,padx=2是button空间中自己的数据变量,是在自己的packing space中增加space,会使button部件增大;而eg2中,则是在.中放置一个button,并且使.的packing space增大2,所以会导致button部件会有一个相应的位移。
eg3:
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
eg3 与 eg1 的原理类似,但是它并不改变button的内部数据,而是通过对.这个空间的参数进行改变来达到更改button部件大小的功能。
-expand true选项可以让部件扩展它的填充区域到packing cavity。它让该部件出现在父部件的中央(Center),并且它一般与-fill both联用。
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
-anchor 选项可以将部件定位到它的填充区域中。默认位置是中心(Center)。可选的参数有 n, ne, e, se, s, sw, w, nw的指南针方向。
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)