Tcl 隐藏/显示小部件的最佳方法

Tcl 隐藏/显示小部件的最佳方法,tcl,tk,Tcl,Tk,我想知道这个方法是否适合隐藏或显示小部件 也许是更好的方法 提前谢谢 ttk::treeview .tree .tree insert {} end -id "Item 1" -text "Item 1" .tree insert {} end -id "Item 2" -text "Item 2" .tree insert {} end -id "Item 3" -text "Item 3" text .text -bg green button .b -text "H" -width

我想知道这个方法是否适合隐藏或显示小部件 也许是更好的方法

提前谢谢

ttk::treeview .tree

.tree insert {} end -id "Item 1" -text "Item 1"
.tree insert {} end -id "Item 2" -text "Item 2"
.tree insert {} end -id "Item 3" -text "Item 3"

text .text -bg green

button .b -text "H" -width 10 -command {grid .text -row 0}
button .b1 -text "B" -width 10 -command {grid .text -row 1}

wm geometry . 500x600

grid .tree -row 0 -columnspan 2 -sticky nsew
grid .text -row 1 -columnspan 2 -sticky nsew
grid .b -row 2 -sticky nsw
grid .b1 -row 2 -column 1 -sticky nse

grid columnconfigure . 0 -weight 1
grid rowconfigure . 0 -weight 1

您可以使用
网格删除
。将按钮更改为:

button .b -text "H" -width 10 -command {grid remove .tree}
button .b1 -text "B" -width 10 -command {grid .tree}
当然,如果您还希望文本区域扩展到第0行,您可以 可能还需要修改文本区域的行

grid remove
将记住配置设置


参考资料:

我认为这取决于你真正想要什么。如果要保留原始的
网格
配置以便再次使用此小部件,应使用
网格删除
。但如果您不打算在隐藏后使用该小部件,则应使用
grid-forget