- 论坛徽章:
- 0
|
回复 #4 retuor 的帖子
非常感谢你,已经根据你说的解决了。谢谢!!
做如下调整就OK了。
# -*- coding: cp936 -*-
import wx
import wx.grid
import MySQLdb
# Create a connection object and create a cursor
Con = MySQLdb.connect(host='localhost',user='root',passwd='26817873',db='cmcheck')
Cursor = Con.cursor()
# Make SQL string and execute it
sql = "select cmts,ip,mac from cmmonitor;"
Cursor.execute(sql)
# Fetch all results from the cursor into a sequence and close the connection
Results = Cursor.fetchall()
Con.close()
class TestTable(wx.grid.PyGridTableBase):
def __init__(self):
wx.grid.PyGridTableBase.__init__(self)
self.colLabels = ["Cmts", "ip地址","mac地址"]
def GetNumberRows(self):
return 30
def GetNumberCols(self):
return 3
def IsEmptyCell(self, row, col):
return False
def SetValue(self, row, col, value):
pass
def GetColLabelValue(self, col):
return self.colLabels[col]
def GetValue(self, row, col):
return "%s" % Results[row][col]
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Ip对应的MAC地址",
size=(400,200))
grid = wx.grid.Grid(self)
table = TestTable()
grid.SetTable(table, True)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop() |
|