Notebook+panel+color curiosity

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()

Should have given my version info: wxPython 2402, Python 222, Linux.

While I'm at it, here's a version with a few new lines. A sizer is
needed when using the wrapper to make the inner panel fill it.

-Chuck

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)
  # make the inner panel fill the outer
  sizer = wxBoxSizer(wxHORIZONTAL)
  sizer.Add(p2, 1, wxEXPAND)
  p.SetSizer(sizer)
  nb.AddPage(p, "foo")

frame.Show(1)
app.MainLoop()

···

On Wednesday 12 March 2003 04:08 am, Chuck Esterbrook wrote:

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 Esterbrook wrote:

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?

It's an old bug that no one has figured out a fix for yet:

https://sf.net/tracker/?func=detail&aid=216861&group_id=9863&atid=109863

also:

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!