[wxPython-users] How to change background color in dialogs?

Robin Dunn robin at alldunn.com
Thu May 3 21:00:41 PDT 2007


Jerry LeVan wrote:

> 
> The problem appears to nasty on the mac ...
> 
> For a "Simple Colored background" it *appears* that SetBackgroundColour 
> cannot be called
> for a frame. Consider this example from WxIA.
> 
> *************************
> import wx
> 
> class Frame(wx.Frame):
>     pass
> 
> class App(wx.App):
> 
>     def OnInit(self):
>         self.frame = Frame(parent=None, title='Spare')
>         #self.frame.SetBackGroundColour("light blue")
>         self.panel = wx.Panel(parent=self.frame)
>         self.panel.SetBackgroundColour("light blue")
>         self.frame.Show()
>         self.SetTopWindow(self.frame)
>         return True
> 
> if __name__ == '__main__':
>     app = App()
>     app.MainLoop()
> *****************
> Run as above I get a light blue panel, good!
> 
> If I uncomment the SetBackgroundColor call for the frame and
> comment out the two "panel" statements, the program shows
> a fragment of a window and immediately dies with no error messages.

Pass redirect=False to the App constructor.  You'll then see this 
because of your typo:

Traceback (most recent call last):
   File "/h/tmp/test/frame2.py", line 18, in <module>
     app = App(False)
   File "/projects/wx2.8/wxPython/wx/_core.py", line 7757, in __init__
     self._BootstrapApp()
   File "/projects/wx2.8/wxPython/wx/_core.py", line 7354, in _BootstrapApp
     return _core_.PyApp__BootstrapApp(*args, **kwargs)
   File "/h/tmp/test/frame2.py", line 10, in OnInit
     self.frame.SetBackGroundColour("light blue")
AttributeError: 'Frame' object has no attribute 'SetBackGroundColour'


> 
> Ok, it looks like a panel is necessary for colored backgrounds.

But this is still true.  Top level windows on Mac can't have a bg color.


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





More information about the wxpython-users mailing list