CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2010
    Posts
    2

    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:

    Code:
    #!/usr/bin/env python
    
    FRAMETITLE = 'Basic Frame test'
    APPNAME   = 'Basic Frame'
    
    import wx
    
    class MainFrame(wx.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
            self.Center()
            self.SetBackgroundColour('blue')
            # 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')
            menubar.Append(menu, '&File')
            menu = wx.Menu()
            menu.Append(wx.ID_ABOUT, '&About basicframe', 'About '+APPNAME)
            menubar.Append(menu, '&Help')
            self.SetMenuBar(menubar)
            # tool bar
            # form
            # status bar
            self.CreateStatusBar()
            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):
            self.Close(True)
        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)
            dlg.ShowModal()
            dlg.Destroy()
    
    class TheApp(wx.App):
        def OnInit(self):
            frame = MainFrame(None, wx.ID_ANY, FRAMETITLE)
            frame.Show(True)
            self.SetTopWindow(frame)
            return True
    
    if __name__ == '__main__':
        app = TheApp(0)
        app.MainLoop()
    I'm using Python 2.5.1 under Mac OS X 10.5.8, and wx.__version__ is 2.8.4.0.

    Thanks for any help.

  2. #2
    Join Date
    Mar 2011
    Posts
    2

    Re: wxPythonMac SetBackgroundColour() Fails silently for the Main Window

    I am new to this, but maybe, wx.BLUE, instead of 'Blue'.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured