python利用wx.grid网格显示数据
首先需要定义类似数据模板的类。
import wx.grid as grid class MyDataTable(grid.PyGridTableBase): def __init__(self,data,colLabels=None): grid.PyGridTableBase.__init__(self) self.colLabels = colLabels self.data = data def 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): pass def GetColLabelValue(self,col): if self.colLabels: return self.colLabels[col]
调用设置表格显示。
class ShowData: @classmethod def showSqlData(self,data,grid): table = MyDataTable(data[1],data[0]) grid.SetTable(table) grid.AutoSize() grid.Refresh()