Reputation: 20916
I did see this piece of code in a book and provoked my few questions on inheritance,
txt.py
class LoginPanel(wx.Panel):
def __init__(self,parent)
super(LoginPanel,self).__init__(parent)
self._username = wx.TextCtrl(self)
self._password = wx.TextCtrl(self,style=wx.TE_PASSWORD)
sizer = wx.FlexGridSizer(2,2,8,8)
sizer.Add(wx.StaticText(self,label="Username:"),
0,wx.ALIGN_CENTER_VERTICAL)
sizer.Add(self._username,0,wx.EXPAND)
sizer.Add(wx.StaticText(self,label="Password"),
0,wx.ALIGN_CENTER_VERTICAL)
sizer.Add(self._password,0,wx.EXPAND)
msizer = wx.BoxSizer(wx.VERTICAL)
msizer.Add(sizer,1,wx.EXPAND|wx.ALL,20)
btnszr = wx.StdDialogButtonSizer()
button = wx.Button(self, wx.ID_OK)
button.SetDefault()
btnszr.AddButton(button)
msizer.Add(btnszr,0,wx.ALIGN_CENTER|wx.ALL,12)
btnszr.Realize()
self.SetSizer(msizer)
How can we use the SetSizer method thats part of the Window object directly? Is that how do we use the parent methods without any reference?
Upvotes: 0
Views: 745
Reputation: 33111
Any time you inherit from a class, it gets the methods of that class. If you were to import wx.Panel and do this:
dir(wx.Panel)
You'd get a whole bunch of methods and properties. If you did that same thing to your subclass, you'd get the same list plus whatever methods and properties you created in your subclass. And yes, you have to use "self.SomeMethod" to access the methods from the parent class AND for the ones you create yourself.
Upvotes: 1