如果我有一个带有三个电子表格小部件的笔记本,那么对电子表格进行更改的最佳方法是更新词典(或sqlite文件?).是否所有wx网格对象都带有与SetNumberRows和SetNumberCols相关的内置字典?基本上,我正在寻找有关如何使用电子表格小部件中的用户输入数据的指南,如本示例所述(改编自python.org上的教程):
class ExSheet(wx.lib.sheet.CSheet):
def __init__(self, parent):
sheet.CSheet.__init__(self, parent)
self.SetLabelBackgroundColour('#CCFF66')
self.SetNumberRows(50)
self.SetNumberCols(50)
class Notebook(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
nb = wx.Notebook(self, -1, style=wx.NB_BOTTOM)
self.sheet1 = ExSheet(nb)
self.sheet2 = ExSheet(nb)
self.sheet3 = ExSheet(nb)
nb.AddPage(self.sheet1, "Sheet1")
nb.AddPage(self.sheet2, "Sheet2")
nb.AddPage(self.sheet3, "Sheet3")
self.sheet1.SetFocus()
self.StatusBar()
解决方法:
这是一个简单的示例:
import wx, wx.grid
class GridData(wx.grid.PyGridTableBase):
_cols = "a b c".split()
_data = [
"1 2 3".split(),
"4 5 6".split(),
"7 8 9".split()
]
def GetColLabelValue(self, col):
return self._cols[col]
def GetNumberRows(self):
return len(self._data)
def GetNumberCols(self):
return len(self._cols)
def GetValue(self, row, col):
return self._data[row][col]
def SetValue(self, row, col, val):
self._data[row][col] = val
class Test(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.data = GridData()
grid = wx.grid.Grid(self)
grid.SetTable(self.data)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.Show()
def OnClose(self, event):
print self.data._data
event.Skip()
app = wx.PySimpleApp()
app.TopWindow = Test()
app.MainLoop()