[Tutor] OOP / Classes questions
stefan at lsd.co.za
Fri Apr 10 20:44:37 CEST 2009
I am a relative newbie to python and OOP concepts and am trying to
work through wxpython. I've seen understanding classes is essential to
this and have been trying to work through them.
I have a few questions re the below code (i suspect its due to a lack
of my understanding of classes)
1. I am not sure why / when you use the self. notation. I understand
that self refers to the instance you create, so you can have multiple
instances and the class knows which one you are talking about.
Why do they use self.Bind or similar and at other times use file =
(without the self)
2. In the Bind( they use self.OnQuit which seems to call the function
OnQuit). Again, why is it self.OnQuit?
3. def OnQuit(self, event): - where does event here come from and what
does it do with it?
I guess as a general kind of question, can anyone recommend some
tutorial or documentation re OOP and classes?
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(250, 150))
menubar = wx.MenuBar()
file = wx.Menu()
quit = wx.MenuItem(file, 1, '&Quit\tCtrl+Q')
self.Bind(wx.EVT_MENU, self.OnQuit, id=1)
def OnQuit(self, event):
app = wx.App()
MenuExample(None, -1, '')
More information about the Tutor