首先需要定义类似数据模板的类。
import wx.grid as gridclass MyDataTable(grid.PyGridTableBase):def __init__(self,data,colLabels=None):grid.PyGridTableBase.__init__(self)self.colLabels = colLabelsself.data = datadef GetNumberRows(self):return len(self.data)def GetNumberCols(self):return len(self.data[0])def GetValue(self,row,col):if self.data[row][col] is None:return ''else:return self.data[row][col]def SetValue(self,row,col,value):passdef GetColLabelValue(self,col):if self.colLabels:return self.colLabels[col]
调用设置表格显示。
class ShowData:@classmethoddef showSqlData(self,data,grid):table = MyDataTable(data[1],data[0])grid.SetTable(table)grid.AutoSize()grid.Refresh()