0

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?

1
  • Incidentally, that seems to be an older tutorial. Most people try to avoid super(). For that code it's better to call wx.Panel.__init__() directly. Commented Aug 29, 2012 at 1:32

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.