效果:
代码:
import wx.grid
class SimpleGrid(wx.grid.Grid):
def __init__(self, parent):
wx.grid.Grid.__init__(self, parent, -1)
data = (
('bob', 28),
('steve', 30),
('jack', 20),
('mike', 18),
('avirl', 33)
)
col_labels = ('Name', 'Age')
rows = len(data)
cols = len(col_labels)
self.CreateGrid(rows, cols)
for i in range(cols):
self.SetColLabelValue(i, col_labels[i])
for i in range(rows):
self.SetRowLabelValue(i, str(i))
for j in range(cols):
self.SetCellValue(i, j, str(data[i][j]))
class TestFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, 'My Grid', size=(275, 275))
SimpleGrid(self)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = TestFrame(None)
frame.Show(True)
app.MainLoop()