If I put a panel directly into a notebook, I cannot set its background
color at all; it's always gray. But if I wrap the panel in another
panel, then I can.
Code below. Change "if 0" to "if 1" to demonstrate the problem.
Anyone know what's going on here?
I'm also having some problems where a panel in a notebook appears to
reorder its children on display updates. I'll see if "panel wrapping"
fixes that one too.
···
--
Chuck
http://ChuckEsterbrook.com
from wxPython.wx import *
color = wxColor(85, 170, 255)
class MyPanel(wxPanel):
def __init__(self, *posArgs, **kwArgs):
wxPanel.__init__(self, *posArgs, **kwArgs)
self.SetBackgroundColour(color)
wxStaticText(self, -1, "Hello, world.")
app = wxPySimpleApp()
frame = wxFrame(None, -1, "")
nb = wxNotebook(frame, -1)
if 0:
# put MyPanel directly in the notebook
# cannot change background color
p = MyPanel(nb, -1)
nb.AddPage(p, "foo")
p.SetBackgroundColour(color) # futile attempt to force the issue
else:
# wrap MyPanel in an arbitrary second panel
# now background color change is respected.
p = wxPanel(nb, -1)
p2 = MyPanel(p, -1)
nb.AddPage(p, "foo")
frame.Show(1)
app.MainLoop()