I got this error when i was running a tuturial on how to view data using a grid in wx. I downloaded the modules for wx. I wandering if anyone can help me. this is the error i got
Traceback (most recent call last):
File "C:\Update\data.py", line 7, in <module>
class MyFrame(wx.Frame):
File "C:\Update\data.py", line 27, in MyFrame
self.grid_1.SetColLabelValue(index, item[0])
NameError: name 'self' is not defined
This is the code i put in.
import wx
import wx.grid
import getdata
db = getdata.Eb_db()
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.grid_1 = wx.grid.Grid(self, -1, size=(1, 1))
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("frame_1")
self.SetSize((400, 400))
# end wxGlade
self.grid_1.CreateGrid(len(db.data),len(db.fields))
for item in db.fields:
index = 0
self.grid_1.SetColLabelValue(index, item[0])
index += 1
for row in range(len(db.data)):
for col in range(len(db.data[row])):
values = db.data[row][col]
self.grid_1.SetCellValue(row,col,str(values))
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 =wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.grid_1, 1, wx.EXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
self.Layout()
# end wxGlade
# end of class MyFrame
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()
got the example on this site: http://www.serpia.org/mysql. If you know any other tutorials i can try to view data from mysql database.