Вы определяете свой статический текст как дочерний элемент pnl, а не midPnl
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id=wx.ID_ANY, title="", size=(360,100)):
super(MyFrame, self).__init__(parent, id, title, size)
pnl = wx.Panel(self)
pnl.SetBackgroundColour('#4f5049')
vbox = wx.BoxSizer(wx.VERTICAL)
midPan = wx.Panel(pnl)
midPan.SetBackgroundColour('green')
vbox.Add(midPan,wx.ID_ANY, wx.EXPAND |wx.ALL, 20)
sizer = wx.GridBagSizer(10,5)
st1=wx.StaticText(midPan,label='Black on green')
st2=wx.StaticText(midPan,label='White on green')
st2.SetForegroundColour('white')
st3=wx.StaticText(midPan)
st3.SetLabelMarkup("<span foreground='black' background='red'>Black on red</span>")
st4=wx.StaticText(midPan)
st4.SetLabelMarkup("<span foreground='white' background='red'>White on red</span>")
sizer.Add(st1, pos=(1,1),flag=wx.ALL,border=5)
sizer.Add(st2, pos=(2,2),flag=wx.ALL,border=5)
sizer.Add(st3, pos=(3,3),flag=wx.ALL,border=5)
sizer.Add(st4, pos=(4,1),flag=wx.ALL,border=5)
midPan.SetSizer(sizer)
pnl.SetSizer(vbox)
self.Show()
if __name__ == "__main__":
app = wx.App()
frame = MyFrame(None,title="The Main Frame")
app.MainLoop()