调整表格列表的大小
我可以在不重新创建小部件的情况下调整表格列表的大小吗?
我有两个表格列表小部件(每个小部件都位于一个网格中)。 一个始终显示,另一个隐藏,直到您按下按钮。 当第二个表列表也显示时,我想将第一个表列表的大小调整为行数的一半(出于屏幕可读性的原因)。 然后,如果您关闭第二个表列表,我会将第一个表列表返回到其原始高度(初始行数)。 我怎样才能做到这一点? (注意:问题主要是关于是否可以动态调整 nemethi 的表列表的大小。)
Can I resize a tablelist without recreate the widget?
I have two tablelist widgets (each into a grid).
One is always displayed, the other is hidden until you press a button.
When the second tablelist is displayed as well, I want resize the first one to half the number of rows (for reasons of screen's readability).
Then, if you close the second tablelist, I would come back the first to its original height (initial number of rows).
How can I achieve this?.
(NOTE:the question is mainly about if is possible resize a nemethi's tablelist in dynamic way.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所有 Tk 小部件都有它们想要的大小,但可以处理小于该大小的大小。所以我们需要利用这一点。
您有一个容器(顶层或可能是框架),它将包含两个表列表小部件(或者当只显示一个时仅包含其中一个)。当添加第二个表列表时,我们希望保持整个容器的大小相同。最简单的方法是使用
place
几何管理器 - 在本例中,尤其是其相对位置和大小调整控件 - 因为这可以让您更精确地控制小部件大小。 (缺点是您必须自己做一些工作才能获得正确的初始小部件尺寸。)在下面的代码中,我假设容器小部件称为
.container< /code>,主小部件称为
.container.main
,额外的小部件称为.container.extra
。设置方法:如何添加
.container.extra
:如何删除
.container.extra
:另请注意,由于使用
place 会增加复杂性
,你最好将它用于尽可能少的小部件;在框架上使用它,然后将其打包
/grid
到 GUI 的其余部分(用于切换第二个表格列表显示的按钮等)All Tk widgets have a size that they'd prefer to be, but can cope with less than that. So we need to take advantage of this.
You've got a container (a toplevel or possibly a frame) that will contain the two tablelist widgets (or just one of them when only one is meant to be displayed). When the second tablelist is added, we want to keep the size of the overall container the same. The simplest method of doing this is with the
place
geometry manager — in this case, especially its relative placement and sizing controls — since that lets you control widget sizing more precisely. (The down-side is that you have to do some work yourself to get initial widget sizes right.)In the code below, I'm assuming that the container widget is called
.container
, the main widget is called.container.main
and the extra is called.container.extra
. To set things up:How to add
.container.extra
:How to remove
.container.extra
:Also note that because of the general increased trickiness of using
place
, you're better off using it for as few widgets as possible; use it on a frame that you thenpack
/grid
into the rest of your GUI (your button for togggling display of the second tablelist, etc.)