2010-03-10 605 views
0

我正在使用wxPython網格,但我無法設置它的背景顏色(沒有填充單元格的網格部分)。我嘗試與grid.SetBackgroundColour,但沒有運氣;顯示的背景色始終是窗口的默認系統顏色。如何設置wxPython網格背景顏色?

wx.version() - > 2.8.10.1(MSW-的unicode)

內容sys.version - > 2.5(R25:51908,2006年9月19日,9點52分17秒)[MSC v.1310 32 (英特爾)]

O/S版本 - > Windows XP SP3,但我嘗試使用基於Ubuntu的Python live cd,結果相同。

import wx 
import wx.grid 

class TestFrame (wx.Frame): 
    def __init__ (self): 
     wx.Frame.__init__ (self, None, title="Grid Table", size=(640,480)) 

     grid = wx.grid.Grid(self, size=(300,300)) 
     grid.CreateGrid(2,2) 
     grid.SetCellValue(0,0,"1") 

     color = (100,100,255) 
     attr = self.cellAttr = wx.grid.GridCellAttr() 
     attr.SetBackgroundColour(color) 

     # for row, col in 
     for row in xrange(2): 
      for col in xrange(2): 
       grid.SetAttr(row, col, attr) 

     grid.SetBackgroundColour(color)  # <<< This don't work! 

app = wx.PySimpleApp() 
frame = TestFrame() 
frame.Show() 
app.MainLoop() 

回答

2

grid.SetDefaultCellBackgroundColour(color)將着色所有內容,包括單元格外的區域。

+0

很好,謝謝!我錯過了文檔中的數百種顏色和顏色:) – PabloG 2010-03-10 16:02:01