Introduction

Most GUI programs display a splash screen before launching real applications. This snippet demonstrates the basics of how to use a wx.SplashScreen in an application.

What Objects are Involved

Process Overview

Once launched, this recipe shows a JPEG image (the wxPyWiki logo) at the center of a screen for one second: http://wiki.wxpython.org/wxPyWiki.jpg
Then this window titled "Hello from wxPython" appears: http://wxpython.org/images/intro01.gif

Special Concerns

Code Sample

##
## DO NOT EDIT
##
#----------------------------------------------------------------------#
# This is a minimal wxPython program to show a SplashScreen widget.
#
# Tian Xie
# 3/8/2005
#----------------------------------------------------------------------#

import wx

class MyGUI(wx.Frame):
    """
Hello World!
    """
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
# Put more GUI code here for a fancier application.
#----------------------------------------------------------------------#

class MySplashScreen(wx.SplashScreen):
    """
Create a splash screen widget.
    """
    def __init__(self, parent=None):
        # This is a recipe to a the screen.
        # Modify the following variables as necessary.
        aBitmap = wx.Image(name = "wxPyWiki.jpg").ConvertToBitmap()
        splashStyle = wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT
        splashDuration = 1000 # milliseconds
        # Call the constructor with the above arguments in exactly the
        # following order.
        wx.SplashScreen.__init__(self, aBitmap, splashStyle,
                                 splashDuration, parent)
        self.Bind(wx.EVT_CLOSE, self.OnExit)

        wx.Yield()
#----------------------------------------------------------------------#

    def OnExit(self, evt):
        self.Hide()
        # MyFrame is the main frame.
        MyFrame = MyGUI(None, -1, "Hello from wxPython")
        app.SetTopWindow(MyFrame)
        MyFrame.Show(True)
        # The program will freeze without this line.
        evt.Skip()  # Make sure the default handler runs too...
#----------------------------------------------------------------------#

class MyApp(wx.App):
    def OnInit(self):
        MySplash = MySplashScreen()
        MySplash.Show()

        return True
#----------------------------------------------------------------------#

app = MyApp(redirect=True, filename = "demo.log")
app.MainLoop()

Comments

Reference

wx.SplashScreen

SplashScreen (last edited 2008-09-25 17:42:28 by host-72-174-168-209)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.