在tk或者wxpython中,怎样将数据库查询的数据用表格显示出来,具体代码怎么写
1个回答
展开全部
#coding=utf-8
import wx
import wx.grid
class TestTable(wx.grid.PyGridTableBase):
def __init__(self):
wx.grid.PyGridTableBase.__init__(self)
#下面代替取出的数据
self.data = [ [1, 1],
[2, 2] ,
[3, 3] ,
[4, 4] ,
]
# these five are the required methods
def GetNumberRows(self):
return len(self.data)
def GetNumberCols(self): return len(self.data[0])
def IsEmptyCell(self, row, col): return True
def GetValue(self, row, col): return self.data[row][col]
def SetValue(self, row, col, value): pass
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title = "Grid Table",
size = (640, 480))
grid = wx.grid.Grid(self)
table = TestTable()
grid.SetTable(table, True)
app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()
import wx
import wx.grid
class TestTable(wx.grid.PyGridTableBase):
def __init__(self):
wx.grid.PyGridTableBase.__init__(self)
#下面代替取出的数据
self.data = [ [1, 1],
[2, 2] ,
[3, 3] ,
[4, 4] ,
]
# these five are the required methods
def GetNumberRows(self):
return len(self.data)
def GetNumberCols(self): return len(self.data[0])
def IsEmptyCell(self, row, col): return True
def GetValue(self, row, col): return self.data[row][col]
def SetValue(self, row, col, value): pass
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title = "Grid Table",
size = (640, 480))
grid = wx.grid.Grid(self)
table = TestTable()
grid.SetTable(table, True)
app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询