2016-07-29 39 views
-1

我想知道這是否是一個好方法用於隱藏或顯示控件 也許更好的方法?最好的方法/顯示控件

在此先感謝

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 

回答

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

+0

是網格中刪除。看起來更好,謝謝布拉德 – Mkn

0

我認爲這是取決於你真正想要的。如果您想保留原始grid配置以再次使用此小部件,則應使用grid remove。但是,如果你不打算使用控件一次隱藏後,你應該使用grid forget