2012-09-25 27 views
1

我是TCL Tk的新手,我正在使用Tk表在我的GUI中創建表。如何禁用TCL Tk表中的完整列Tk

Basically it contains some hardware register's info like its name, address, value....etc. 
Now i want that user should not be able to change the register address and name and hence i 

想要完全禁用Tk表的名稱和地址列。任何人都可以告訴我我該如何做到這一點。我很長一段時間試着這個。請幫幫我 。

回答

1

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 
+0

用戶可以模擬一個表格部件以'TTK ::通過關閉樹「列」 treeview'。 –

0

,你也可以使用任何選項-titlerows「N」-titlecols「M」聲明,第一個「N」行只讀標題或第一「M」的cols讀只有標題。

希望我幫