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

时间:2016-07-29 15:29:39

标签: 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 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

2 个答案:

答案 0 :(得分:1)

您可以使用grid remove。将按钮更改为:

button .b -text "H" -width 10 -command {grid remove .tree}
button .b1 -text "B" -width 10 -command {grid .tree}

当然,如果您还希望文本区域扩展到第0行,那么您 也可能想要修改文本区域的行。

grid remove会记住配置设置。

参考文献:http://tcl.tk/man/tcl8.6/TkCmd/grid.htm

答案 1 :(得分:0)

我认为这取决于你真正想要的东西。如果您想保留原始grid配置以便再次使用此小部件,则应使用grid remove。但是,如果您不想在隐藏后使用窗口小部件,则应使用grid forget