wx.Panels.init(parent=[wx.Frame | wx.Panel | wx.Window])
Panels need another wx widget as its parent. The wx.Frame class can set “parent” to None in its init() method.
Doing obj=B() sets the panel class B’s init(parent) argument to “None” which is not a valid value.
Try
mysubdPanel = B(self)
where self is assigned to the “parent” keyword or more explicitly if you changed your panel class’ init keyword argument names then try
mysubdPanel = B(parent=self) or
mysubdPanel = B(parent=self.parentPanel) or the like
···
The following code works fine for me.
import wx
class AppBasePanel(wx.Panel):
def init(self, *args, **kwargs):
wx.Panel.init(self, *args, **kwargs)
self.SetBackgroundColour(‘Blue’)
st = wx.StaticText(self, label=str(self))
class SubclassedPanel(AppBasePanel):
def init(self, *args, **kwargs):
AppBasePanel.init(self, *args, **kwargs)
self.SetBackgroundColour(‘Green’)
class Frame(wx.Frame):
def init(self, *args, **kwargs):
wx.Frame.init(self, *args, **kwargs)
basePanel = AppBasePanel(parent=self)
subclassedPanel = SubclassedPanel(parent=self)
sizer=wx.BoxSizer(wx.VERTICAL)
sizer.Add(basePanel, 1, wx.EXPAND|wx.ALL, 5)
sizer.Add(subclassedPanel, 1, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
if name == “main”:
app = wx.App()
frame = Frame(parent=None, title=‘Test Subclassed Panels’)
frame.Show()
app.MainLoop()