Join Club ShowMeDo to Learn Python!

This series is a part of Club ShowMeDo. Click to learn why you should join our club with a simple monthly subscription.

  • We teach Python and all the cool modules
  • Topics include beginner Python, GUIs, Web and Desktop Apps
  • Long, specially crafted video tutorials just for you
  • Club video tutorials extend our normal Free content
  • Save your time - we've done the research for you
  • Keep your skills up-to-date
  • Learn at your own pace, everything you need is shown to you
  • Over 12 hours of archived material are waiting for you in the club

Name: [002] Ian Ozsvald
Member: 128 months
Authored: 181 videos
Description: I am the co-founder of ShowMeDo (see, author of `The Screencasting Handbook <>`_ and the founder of the professional screencast production company `ProCasts <>`_: .. image:: ...

Exercise - Add an HTML About Dialog to the Help menu [ID:557] (11/14)

in series: Build a wxPython Image Viewer

(Showmedo is undergoing major changes. To report any problems viewing the videos please email us and include browser and OS specifics. Cheers - Kyran.)

In this episode we'll add an About box to the Help menu. Most programs that are released to users have an About box - ours will be no exception. We'll use an HTML box so we can easily create a nice message for the user. First we add the menu items for About, then you have to write an OnAbout function which calls our derived Dialog. Finally you will add a new 'ok' wx.Button to the Dialog for the user. A fully worked solution appears in the next episode.

Links - Html Window and Button.

import os
import wx
import wx.html # ADD THIS to use the HtmlWindow


class ImageViewerAbout(wx.Dialog):    
    """This AboutBox is built from Robin Dunn and Noel Rappin's
    excellent wxPython in Action book, see page 178+ for the About HTML box
    and page 174+ for a short discussion on BoxSizers"""
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, -1, 'About the ShowMeDo Image Viewer...',
        html = wx.html.HtmlWindow(self)
        # TODO set longer and more interesting html
        html.SetPage("<p>Some <b>bold</b> text</p>")
        # TODO create a 'button' object from wx.Button, give it the ID wx.ID_OK and text 'Okay'
        # note that your button won't be shown anywhere yet, you have to add it to the sizer below
        # If a button has an ID of wx.ID_OK it will automatically close a wx.Dialog when pressed
        # Create a BoxSizer which grows in the vertical direction
        sizer = wx.BoxSizer(wx.VERTICAL)
        # Add the html window, tell it to take a 100% portion of the *available* area
        # and to EXPAND in ALL directions.  Use a border of 5 pixels around ALL sides of the button
        sizer.Add(html, 1, wx.EXPAND|wx.ALL, 5)
        # TODO Add the button to sizer, tell it to grow by 0% proportionally to the other items
        # Your first button will probably align to the left with no border if you just
        # specify the first 2 arguments to Add
        # BONUS if you can ALIGN_CENTER
        # BONUS if you can give it a 5 pixel border around ALL sides
        # Tell our Dialog to use this new Sizer
        # Tell our Dialog to calculate the size of its items.  Good practice to always do this

class Frame(wx.Frame):
    def __init__(self, parent, id, title):
        style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER) # XOR to remove the resizeable border        
        wx.Frame.__init__(self, parent, id, title=title, size=MAIN_WINDOW_DEFAULT_SIZE, style=style)
        self.Center() # open in the centre of the screen
        self.panel = wx.Panel(self)
        self.panel.SetBackgroundColour('White') # make the background of the window white

        # create a StatusBar and give it 2 columns
        self.statusBar = self.CreateStatusBar()
        self.statusBar.SetStatusText('No image specified', 1)
        self.bitmap = None # set to None as we refer to it in ShowBitmap before we instantiate it
    def CreateMenuBar(self):
        "Create a menu bar with Open, Exit items"
        menuBar = wx.MenuBar()
        # Tell our Frame about this MenuBar
        menuFile = wx.Menu()
        menuBar.Append(menuFile, '&File')
        # NOTE on wx ids - they're used everywhere, we don't care about them
        # Used to handle events and other things
        # An id can be -1 or wx.ID_ANY, wx.NewId(), your own id
        # Get the id using object.GetId()
        fileOpenMenuItem = menuFile.Append(-1, '&Open Image', 'Open a picture')
        #print "fileOpenMenuItem.GetId()", fileOpenMenuItem.GetId()
        self.Bind(wx.EVT_MENU, self.OnOpen, fileOpenMenuItem)

        # add a 'mirror' option, disable it for now
        # we add mirrorMenuItem to self so that we can reference it later
        self.mirrorMenuItem = menuFile.Append(-1, '&Mirror Image', 'Mirror the image horizontally')
        self.mirrorMenuItem.Enable(False) # we can't mirror an image until we've loaded one in, so start with 'mirror' disabled
        self.Bind(wx.EVT_MENU, self.OnMirrorImage, self.mirrorMenuItem)
        # create a menu item for Exit and bind it to the OnExit function       
        exitMenuItem = menuFile.Append(-1, 'E&xit', 'Exit the viewer')        
        self.Bind(wx.EVT_MENU, self.OnExit, exitMenuItem)
        # add a Help menu with an About item
        menuHelp = wx.Menu()
        menuBar.Append(menuHelp, '&Help')
        helpMenuItem = menuHelp.Append(-1, '&About', 'About screen')
        self.Bind(wx.EVT_MENU, self.OnAbout, helpMenuItem)

    # WRITE THIS 3 line function: def OnAbout(self, event):
    # For the dialog pass in 'self' as the parent argument, as for wx.FileDialog

    def OnMirrorImage(self, event):
        # ask the Image to mirror itself on the x-axis
        self.image = self.image.Mirror()
        # whilst we mirror it and show it, we haven't yet forced a repaint so we won't see it unless we hide the window
        # now we can ask for a refresh which repaints the image

    def OnOpen(self, event):
        "Open an image file, set title if successful"
        # Create a file-open dialog in the current directory
        filters = 'Image files (*.gif;*.png;*.jpg)|*.gif;*.png;*.jpg'
        dlg = wx.FileDialog(self, message="Open an Image...", defaultDir=os.getcwd(), 
                            defaultFile="", wildcard=filters, style=wx.OPEN)
        # Call the dialog as a model-dialog so we're required to choose Ok or Cancel
        if dlg.ShowModal() == wx.ID_OK:
            # User has selected something, get the path, set the window's title to the path
            filename = dlg.GetPath()
            # load the image from the filename
            self.image = wx.Image(filename, wx.BITMAP_TYPE_ANY, -1) # auto-detect file type        
            # set the StatusBar to show the image's size
            self.statusBar.SetStatusText('Size = %s' % (str(self.image.GetSize())) , 1)
            # display the image inside the panel
            # enable the 'Mirror' menu item, it only makes sense to enable it when we've loaded
            # an image as before there would be no image to mirror
        dlg.Destroy() # we don't need the dialog any more so we ask it to clean-up

    def ShowBitmap(self):
        if self.bitmap is not None:
        # Convert to Bitmap for wxPython to draw it to screen
        self.bitmap = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(self.image))       
        # Make the application's window as large as the image
        self.Center() # open in the centre of the screen
    def OnExit(self, event):
        "Close the application by Destroying the object"
class App(wx.App):
    def OnInit(self):
        self.frame = Frame(parent=None, id=-1, title='Image Viewer')
        return True
if __name__ == "__main__":       
    # make an App object, set stdout to the console so we can see errors
    app = App(redirect=False)

Got any questions?

Get answers in the ShowMeDo Learners Google Group.

Video statistics:

  • Video's rank shown in the most popular listing
  • Video plays: 0 (since July 30th)
  • Plays in last week: 0
  • Published: 101 months ago

Thank-yous, questions and comments

If this video tutorial was helpful please take some time to say thank-you to the authors for their hard work. Feel free to ask questions. Let the author know why their video tutorial was useful - what are you learning about? Did the video tutorial save you time? Would you like to see more?

You may also want to see our ShowMeDo Google Group to speak to our active users and authors.

Your email address will not be published.

Show some quick comments >>

All comments excluding tick-boxed quick-comments

This was a really good exercise. Thanks

Very disappointed with

Exercise - Add an HTML About Dialog to the Help menu (episode 11)

Suddenly, after getting incremental information in the first 10 episodes, the student is overwhelmed with a tidal wave of new code to write with little help.

I had to cheat and look at the solved exercise in Ep. 12.

I suggest that you re-author Episode 11 and split it into 2-3 separate episodes with more detailed explanation of the wx methods required.

Video published, thanks for contributing to ShowMeDo

Showmedo is a peer-produced video-tutorials and screencasts site for free and open-source software (FOSS)- with the exception of some club videos, the large majority are free to watch and download.

how to help » about » faq »

Educating the Open-source Community With Showmedo

Although as important as the software it supports, education and documentation are relatively neglected in the Open-source world. Coders love to code, and explaining how best to use or improve the software tends to be deferred or even sidelined.

At Showmedo we believe the community can play a vital role here and also say thanks for the tools and software that make our lives easier. If you have a piece of software you love or a programming langugage you are enthusiastic about, why not make a screencast showing others how to use it? All the stuff you wish you'd been told, the tips, tricks, insights that would have saved you time and frustration.

Screencasting is easier than you think, and we're happy to help you. You can emailus for advice or just use some of the how-to screencasts on the site. This screencasting learning-pathis a good place to start.

Kudos and Thanks for Ian

3 Minute Oveview (What Does Python Look Like?)

simple and informative. you draw me in
70 months ago


Showmedo's development is fairly rapid and bugs will inevitably creep in. If you have any problems please drop us a line using the contact address below. Likewise, any suggestions for improvements to the site are gratefully received.