How do I build an about box

An about box is a good example of a display dialog that displays more complex information than is possible in a plain message box, but doesn't require other functionality. In this case, you can use wx.html.HtmlWindow as a straightforward mechanism to display styled text. Actually, wx.html.HtmlWindow is much more powerful than we show here, and includes methods to manage user interaction and rendering in detail. Chapter 16 covers the features of wx.html.HtmlWindow. Listing 6.10 displays a class that creates an about box using the HTML renderer.

Listing 6.10 Using wx.html.HtmlWindow as an about box class SketchAbout(wx.Dialog):

<body bgcolor="#ACAA60">

<center><table bgcolor="#455481" width="100%" cellspacing="0"

cellpadding="0" border="1">

<td align="center"><h1>Sketch!</h1></td> </tr> </table> </center>

<p><b>Sketch</b> is a demonstration program for <b>wxPython In Action</b>

Chapter 6. It is based on the SuperDoodle demo included with wxPython, available at </p>

<p><b>SuperDoodle</b> and <b>wxPython</b> are brought to you by

<b>Robin Dunn</b> and <b>Total Control Software</b>, Copyright

wx.Dialog._init_(self, parent, -1, 'About Sketch', size=(44 0, 400) )

html = wx.html.HtmlWindow(self) html.SetPage(self.text)

button = wx.Button(self, wx.ID_OK, "Okay")

sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(html, 1, wx.EXPAND|wx.ALL, 5) sizer.Add(button, 0, wx.ALIGN_CENTER|wx.ALL, 5)

self.SetSizer(sizer) self.Layout()

Most of this listing is taken up with the HTML string itself, which has some layout and font tags. The dialog is a combination of wx.html.HtmlWindow, and a button with the wx.ID_OK ID. Clicking the button automatically closes the window, as with any other dialog. A vertical box sizer is used to manage the layout.

Figure 6.8 displays the resulting dialog.

About Sketch @


Sketch is a demonstration program for wxPython In Action Chapter 7. It is based on the SuperDoodle demo included with wxPython. available at

SuperDoodle and wxPython are brought to you by Robin Dunn and Total Control Software, Copyright © 1997-200G.

The HTML about box

To use this, wire up a menu item and a handler as in the following:

def OnAbout(self, event): dlg = SketchAbout(self) dlg.ShowModal() dlg.Destroy()

Was this article helpful?

0 0

Post a comment