传统知识 "grid" 和 "grid remove"

TK "grid" and "grid remove"

我的 TK 应用程序有几个包含不同小部件的框架。 要隐藏框架(及其内容),我使用 grid remove $frame"。 我怎样才能将 TK 顶层的大小调整到所需的最小几何形状?

grid [ttk::frame .f ] -sticky nwse
grid [ttk::frame .f.f] -sticky nwse
foreach el {a b c d e f} {
 grid [label .f.f.$el -text "ELEM $el" ] -sticky nwse
}
update
after 2500
grid remove .f.f

在 "grid remove .f.f" 之后需要什么才能拥有没有标签的顶层尺寸?

而删除小部件 grid remove takes the widget out of the grid, it doesn't forget the information about how to lay that widget out (in case you want to add it back in at the same location, an occasionally useful operation). To really forget it entirely, you should use grid forget 会删除其布局信息。

怎么样:

wm 几何 $toplevel {}

此致,

我很惊讶 wm geometry $toplevel {}。 它重绘了。伟大的。 但这并没有解决我的问题,但现在了解情况。

如果顶层框架(顶层中的第一个也是唯一一个帧)从网格中移除,则顶层为 "empty" 并且不会重绘。

如果网格中的顶层至少达到 widgets/frames,我可以删除一个并完成重绘。

在我的示例中,.e 是辅助框架。没有尺寸没有内容。

package require Tk
grid [frame .e ]
grid [frame .f ] -sticky nwse
foreach el {a b c e f g h} {
    grid [label .f.$el -text "1ELEM $el" ] -sticky nwse
 }
update
after 1000
grid remove .f