2013-06-19 465 views
0

我想更改chaco中表格單元格的背景顏色,但無法成功。我使用traitsui.api的TableEditor並且無法找到它的顏色屬性。您的幫助並建議將不勝感激。以下是代碼的相關部分。更改Chaco表格單元格背景顏色

colors = ["blue", "red", "yellow", "green", "black"] 
colors_name = ["Batch1", "Batch2", "Batch3", "Batch4", "Batch5"] 

class ColorTable(HasTraits): 
    pass  

    color_table = List(Instance(ColorTable)) 
    color_columns = [] 
    color_columns.append(ObjectColumn(name="Name")) 
    color_columns.append(ObjectColumn(name="Value")) 
    color_table_editor=TableEditor(columns=color_columns, 
     deletable = True, 
     sortable = False, 
     sort_model = False, 
     show_lines = True, 
     editable= False, 
     show_column_labels = False) 

    def _updateColorTable(self): 
     del(self.color_table) 
     data = ColorTable()  
     data.Name="Name" 
     data.Value="Color" 
     self.color_table.append(data) 
     for i in range(len(types_name)): 
      data = ColorTable() 
      #exec('data.Name="'+str(colors_name[i])+'"') 
      #exec('data.Value="'+str(colors[i])+'"') 
      data.Name=str(colors_name[i]) 
      data.Value=str(colors[i]) 
      #data.Value.format.cell_bg_color=[10,10,10] 
      self.color_table.append(data) 

回答

0

您可以在初始化ObjectColumn時通過傳遞顏色來更改整列的bgcolor。 ObjectColumn(name =「Value」,cell_color ='red')。但問題是我不知道如何爲每一行設置不同的顏色! Mahmoud:d

+0

謝謝Mahmoud.It會幫助,但我仍然在尋找每個單元格的顏色屬性 – fariborz

相關問題