Splash screen positioning

Hi all,

I want to show a splash screen when my application opens, and I would like it to be centered over the parent frame. I added the following code:

class App(wx.App):
    """
    Main application.
    """
    def OnInit(self):
        splashimg = wx.Image("resources/logo.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        wx.SplashScreen(splashimg, wx.SPLASH_CENTRE_ON_PARENT | wx.SPLASH_TIMEOUT,
            2000, None, -1)
        wx.Yield()
        return True

The image shows fine, but it is centered on screen, not on the parent. While writing this I realized this is likely due to the fact that I have parent set as "None"! However, I am not sure what the parent needs to be. When the script runs it first hits:

if __name__ == '__main__':
     app = App()
     frame = Frame()
     frame.Show()
     print "Awaiting your commands."
     app.MainLoop()

So I tried setting parent for the SplashScreen to "frame", as that is the instance of my main frame, but I get:

NameError: global name 'frame' is not defined

Not quite sure if I should put the splash somewhere else, or how to get the right parent.

Thanks for any help,
Sam

wormwood_3 wrote:

Hi all,

I want to show a splash screen when my application opens, and I would like it to be centered over the parent frame. I added the following code:

class App(wx.App):
    """ Main application.
    """ def OnInit(self):
        splashimg = wx.Image("resources/logo.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        wx.SplashScreen(splashimg, wx.SPLASH_CENTRE_ON_PARENT | wx.SPLASH_TIMEOUT,
            2000, None, -1) wx.Yield()
        return True

The image shows fine, but it is centered on screen, not on the parent. While writing this I realized this is likely due to the fact that I have parent set as "None"! However, I am not sure what the parent needs to be. When the script runs it first hits:

if __name__ == '__main__':
     app = App()
     frame = Frame()
     frame.Show()
     print "Awaiting your commands."
     app.MainLoop()

So I tried setting parent for the SplashScreen to "frame", as that is the instance of my main frame, but I get:

NameError: global name 'frame' is not defined

Not quite sure if I should put the splash somewhere else, or how to get the right parent.

Chicken and egg problem: You are creating the splash in the app's OnInit, which is called from within the app's __init__, so the line "frame = Frame()" hasn't yet been executed.

···

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