December 7th, 2010, 09:05 PM
wxPythonMac SetBackgroundColour() Fails silently for the Main Window
Hello, and thanks for looking at this..
I've used wxPython a lot under GTK, and quite a bit under Windows, but this is my first attempt at doing it under Mac OSX. I'm having trouble setting the background color of my main window frame.
I've tried doing it in mainframe.__init__, I've tried doing it during wx.App.OnInit() processing, I've tried calling ClearBackground() afterwards, along with Refresh() even, I've tried calling SetBackgroundStyle(wx.BG_STYLE_COLOUR) first... I've tried doing it after the call to SetTopLevelWindow, I've tried messing with different window styles... nothing works. Nothing. It always comes up white. Calling SetBackgroundColour() works fine for child windows, but it doesn't work for the main window frame.
Has anyone come across this problem before and found any way of getting SetBackgroundColour() to work for the main window on a Mac? Is this a bug, is there a patch.. does it work for you?
I could set up a child window that fills the main window, I could override the background clearing event and clear the view with a color or blit an image or.. use a buffered window and mess with the buffer.. I could use an html window, or use pyOpenGL, lol.. I can think of any number of round about ways to hack around the problem, but. Why doesn't simply calling SetBackgroundColour() work.
Here's a quick and dirty example that works fine under Linux / GTK, and sets the background color of the main window to blue, but under Mac, the background is still white for me:
I'm using Python 2.5.1 under Mac OS X 10.5.8, and wx.__version__ is 188.8.131.52.
FRAMETITLE = 'Basic Frame test'
APPNAME = 'Basic Frame'
def __init__(self, parent, ID, title, pos=wx.DefaultPosition, size=wx.DefaultSize):
wx.Frame.__init__(self, parent, ID, title, pos, size)
# main window init
# menu bar
menubar = wx.MenuBar()
menu = wx.Menu()
menu.Append(wx.ID_EXIT, 'E&xit\tAlt+X', 'Exit the program')
menu.Append(wx.ID_ANY, '&Open\tCtrl+O', 'Open a file')
menu = wx.Menu()
menu.Append(wx.ID_ABOUT, '&About basicframe', 'About '+APPNAME)
# tool bar
# status bar
self.SetStatusText('This is the status bar')
# menu event maps
wx.EVT_MENU(self, wx.ID_EXIT, self.OnExit)
wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
def OnExit(self, event):
def OnAbout(self, event):
msg = "This test program tests out\n"
msg += "frames, menus, statusbars, and this\n"
msg += "message dialog."
dlg = wx.MessageDialog(self, msg, "About basicframe", wx.OK | wx.ICON_INFORMATION)
frame = MainFrame(None, wx.ID_ANY, FRAMETITLE)
if __name__ == '__main__':
app = TheApp(0)
Thanks for any help.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.