Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

wxPython 101: Creating a Splash Screen

DZone's Guide to

wxPython 101: Creating a Splash Screen

A splash screen is a dialog with a logo or art on it that sometimes includes a message about how far along the app has loaded. Learn how to make one with Python!

· Web Dev Zone ·
Free Resource

Deploy code to production now. Release to users when ready. Learn how to separate code deployment from user-facing feature releases with LaunchDarkly.

A common UI element that you used to see a lot of was the Splash Screen. A splash screen is just a dialog with a logo or art on it that sometimes includes a message about how far along the application has loaded. Some developers use splash screens as a way to tell the user that the application is loading so they don't try to open it multiple times.

wxPython has support for creating splash screens. In versions of wxPython prior to version 4, you could find the splash screen widget in wx.SplashScreen. However, in wxPython's latest version, it has been moved to wx.adv.SplashScreen.

Let's look at a simple example of the Splash Screen:

import wx
import wx.adv

class MyFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial", size=(500,500))

        bitmap = wx.Bitmap('py_logo.png')
        splash = wx.adv.SplashScreen(
                     bitmap, 
                     wx.adv.SPLASH_CENTER_ON_SCREEN|wx.adv.SPLASH_TIMEOUT, 
                     5000, self)
        splash.Show()

        self.Show()


# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame()
    app.MainLoop()

Here we create a subclass of wx.Frame and we load up an image using wx.Bitmap. You will note that wx.Bitmap does not actually require you to only load bitmaps, as I am using a PNG here. Anyway, the next line instantiates our splash screen instance. Here we pass it the bitmap we want to show, a flag to tell it how to position itself, a timeout in milliseconds for how long the splash screen should show itself, and what its parent should be. These are all required arguments.

There are also three additional arguments that the splash screen widget can accept: possize, and style. You will note that in this example we tell the splash screen to center itself onscreen. We could also tell it to center on its parent via SPLASH_CENTRE_ON_PARENT.

You will, of course, need to modify this example to use an image of your own.

Wrapping Up

The splash screen is actually pretty useful if you have an application that takes a long time to load. You can easily use it to distract the user and give the illusion that your application is still responsive even when it hasn't fully loaded yet. Give it a try and see what you think.

Deploy code to production now. Release to users when ready. Learn how to separate code deployment from user-facing feature releases with LaunchDarkly.

Topics:
web dev ,python ,splash screen ,ui development ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}