Tk沒有內置的表格部件,所以我假設您使用的是從here開始的Tktable/Tile。
下面是我扔在一起的一個例子,禁用了2列。基本上,你可以使用-coltag命令和一個函數爲所有你想要編輯的條目分配一個特定的標籤,然後你可以將狀態等屬性應用到該標籤。
package require Tktable
array set cells {
0,0 David 0,1 "1234 Fake st" 0,2 foo
1,0 John 1,1 "444 New York Ave" 1,2 bar
}
# This function returns the tag to assign to all cells in col $col
proc tagCol col {
# If we're name or address column, add the disabledColumn tag to it
if {$col == 0 || $col == 1} {
return disabledColumn;
}
}
table .mytable -rows 2 -cols 3 -variable cells -coltagcommand tagCol
# Disable editing of the disabled column entries
.mytable tag config disabledColumn -state disabled -fg blue
pack .mytable
用戶可以模擬一個表格部件以'TTK ::通過關閉樹「列」 treeview'。 –