wxPython in Action
Noel Rappin and Robin Dunn
  • March 2006
  • ISBN 9781932394627
  • 584 pages

Clear and to the point.

Kevin Ollivier, Software Developer, Tulane University

wxPython in Action is a complete guide to the wxPython toolkit, containing a tutorial for getting started, a guide to best practices, and a reference to wxPython's extensive widget set. After an easy introduction to wxPython concepts and programming practices, the book takes an in-depth tour of when and how to use the bountiful collection of widgets offered by wxPython. All features are illustrated with useful code examples and reference tables are included for handy lookup of an object's properties, methods, and events. The book enables developers to learn wxPython quickly and remains a valuable resource for future work.

About the Technology

wxPython is an open source GUI toolkit for the Python programming language. It offers productivity gains and useful features for any programmer, and is quickly gaining in popularity as a result. The only published source for the wxPython toolkit, co-authored by the toolkit?s developer Robin Dunn, wxPython in Action shows readers why wxPython is a better interface tool than Tkinter, the tool that is distributed with Python.

Because they are often large and complex, GUI programming toolkits can be hard to use. wxPython is a combination of the Python programming language and the wxWidgets toolkit, which allows programmers to create programs with a robust, highly functional graphical user interface, simply and easily. wxPython combines the power of an exceptionally complete user interface toolkit with an exceptionally flexible programming language. The result is a toolkit that is unique in the ease with which complex applications can be built and maintained.

Table of Contents detailed table of contents


1. Welcome to wxPython

1.1. Getting started with wxPython

1.2. Creating the bare-minimum wxPython program

1.2.1. Importing wxPython

1.2.2. Working with applications and frames

1.3. Extending the bare-minimum wxPython program

1.4. Creating the final hello.py program

1.5. What can wxPython do?

1.6. Why choose wxPython?

1.6.1. Python programmers

1.6.2. wxWidget users

1.6.3. New users

1.7. How wxPython works

1.7.1. The Python language

1.7.2. The wxWidgets toolkit

1.7.3. Putting it together: the wxPython toolkit

1.8. Summary

2. Giving your wxPython program a solid foundation

2.1. What do I need to know about the required objects?

2.2. How do I create and use an application object?

2.2.1. Creating a wx.App subclass

2.2.2. Understanding the application object lifecycle

2.3. How do I direct output from a wxPython program?

2.3.1. Redirecting output

2.3.2. Modifying the default redirect behavior

2.4. How do I shut down my wxPython application?

2.4.1. Managing a normal shutdown

2.4.2. Managing an emergency shutdown

2.5. How do I create and use the top-level window object?

2.5.1. Working with wx.Frame

2.5.2. Working with wxPython IDs

2.5.3. Working with wx.Size and wx.Point

2.5.4. Working with wx.Frame styles

2.6. How do I add objects and subwindows to a frame?

2.6.1. Adding widgets to a frame

2.6.2. Adding a menubar, toolbar, or status bar to a frame

2.7. How can I use common dialogs?

2.8. What are some common errors with application objects and frames?

2.9. Summary

3. Working in an event-driven environment

3.1. What terminology do I need to understand events?

3.2. What is event-driven programming?

3.2.1. Coding event handlers

3.2.2. Designing for event-driven programs

3.2.3. Event triggers

3.3. How do I bind an event to a handler?

3.3.1. Working with the wx.EvtHandler methods

3.4. How are events processed by wxPython?

3.4.1. Understanding the event handling process

3.4.2. Using the Skip() method

3.5. What other event properties are contained in the application object?

3.6. How can I create my own events?

3.6.1. Defining a custom event for a custom widget

3.7. Summary

4. Making wxPython easier to handle with PyCrust

4.1. How do I interact with a wxPython program?

4.2. What are the useful features of PyCrust?

4.2.1. Autocompletion

4.2.2. Calltips and parameter defaults

4.2.3. Syntax highlighting

4.2.4. Python help

4.2.5. Command recall

4.2.6. Cut and paste

4.2.7. Standard shell environment

4.2.8. Dynamic updating

4.3. What do the PyCrust notebook tabs do?

4.3.1. Namespace tab

4.3.2. Display tab

4.3.3. Calltip tab

4.3.4. Session tab

4.3.5. Dispatcher tab

4.4. How can I wrap PyCrust around my wxPython application?

4.5. What else is in the Py package?

4.5.1. Working with the GUI programs

4.5.2. Working with the support modules

4.6. How can I use modules from the Py package in my wxPython programs?

4.7. Summary

5. Creating your blueprint

5.1. How can refactoring help me improve my code?

5.1.1. A refactoring example

5.1.2. Starting to refactor

5.1.3. More refactoring

5.2. How do I keep the Model and View separate in my program?

5.2.1. What is a Model-View-Controller system?

5.2.2. A wxPython model: PyGridTableBase

5.2.3. A custom model

5.3. How do you unit-test a GUI program?

5.3.1. The unittest module

5.3.2. A unittest sample

5.3.3. Testing user events

5.4. Summary

6. Working with the basic building blocks

6.1. Drawing to the screen

6.1.1. How do I draw on the screen?

6.2. Adding window decorations

6.2.1. How do I add and update a status bar?

6.2.2. How do I include a submenu or checked menu?

6.2.3. How do I include a toolbar?

6.3. Getting standard information

6.3.1. How do I use standard file dialogs?

6.3.2. How do I use a standard color picker?

6.4. Making the application look nice

6.4.1. How do I lay out widgets?

6.4.2. How do I build an about box?

6.4.3. How do I build a splash screen?

6.5. Summary


7. Working with the basic controls

7.1. Displaying text

7.1.1. How do I display static text?

7.1.2. How can I get the user to enter text?

7.1.3. How do I change the text without user input?

7.1.4. How do I create a multi-line or styled text control?

7.1.5. How do I create a font?

7.1.6. Can I have styled text if my platform doesn’t support rich text?

7.1.7. What if my text control doesn’t match my string?

7.1.8. How do I respond to text events?

7.2. Working with buttons

7.2.1. How do I make a button?

7.2.2. How do I make a button with a bitmap?

7.2.3. How do I create a toggle button?

7.2.4. What’s a generic button, and why should I use one?

7.3. Entering and displaying numbers

7.3.1. How do I make a slider?

7.3.2. How can I get those neat up/down arrow buttons?

7.3.3. How can I make a progress bar?

7.4. Giving the user choices

7.4.1. How do I create a checkbox?

7.4.2. How can I create a group of radio buttons?

7.4.3. How can I create a list box?

7.4.4. Can I combine a checkbox and a list box?

7.4.5. What if I want a pull-down choice?

7.4.6. Can I combine text entry and a list?

7.5. Summary

8. Putting widgets in frames

8.1. The life of a frame

8.1.1. How do I create a frame?

8.1.2. What are some different frame styles?

8.1.3. How do I create a frame with extra style information?

8.1.4. What happens when I close a frame?

8.2. Using frames

8.2.1. What are the methods and properties of wx.Frame?

8.2.2. How do I find a subwidget of a frame?

8.2.3. How do I create a frame with a scrollbar?

8.3. Alternative frame types

8.3.1. How do I create an MDI frame?

8.3.2. What’s a mini-frame and why would I use it?

8.3.3. How do I make a non-rectangular frame?

8.3.4. How can I drag a frame without a title bar?

8.4. Using splitter windows

8.4.1. Creating a splitter window

8.4.2. A splitter example

8.4.3. Changing the appearance of the splitter

8.4.4. Manipulating the splitter programmatically

8.4.5. Responding to splitter events

8.5. Summary

9. Giving users choices with dialogs

9.1. Working with modal dialogs

9.1.1. How do I create a modal dialog?

9.1.2. How do I create an alert box?

9.1.3. How do I get short text from the user?

9.1.4. How can I display a list of choices in a dialog?

9.1.5. How can I display progress?

9.2. Using standard dialogs

9.2.1. How can I use a file picker?

9.2.2. How can I use a font picker?

9.2.3. How can I use a color picker?

9.2.4. Can I allow the user to browse images?

9.3. Creating a wizard

9.4. Showing startup tips

9.5. Using validators to manage data in a dialog

9.5.1. How do I use a validator to ensure correct data?

9.5.2. How do I use a validator to transfer data?

9.5.3. How do I validate data as it is entered?

9.6. Summary

10. Creating and using wxPython menus

10.1. Creating Menus

10.1.1. How do I create a menu bar and attach it to a frame?

10.1.2. How do I create a menu and attach it to the menu bar?

10.1.3. How do I add items to a pull-down menu?

10.1.4. How do I respond to a menu event?

10.2. Working with menu items

10.2.1. How do I find a specific menu item in a menu?

10.2.2. How do I enable or disable a menu item?

10.2.3. How do I associate a menu item with a keyboard shortcut?

10.2.4. How do I create a toggle menu item with a checkbox or radio button?

10.3. Sprucing up your menus

10.3.1. How do I create a submenu?

10.3.2. How do I create a pop-up menu?

10.3.3. How can I create fancier menus?

10.4. Usability guidelines for menus

10.4.1. Keeping menus uniform in length

10.4.2. Creating logical item groups

10.5. Summary

11. Placing widgets with sizers

11.1. What’s a sizer?

11.2. Basic sizers with the grid sizer

11.2.1. What is a grid sizer?

11.2.2. How do you add or remove children from a sizer?

11.2.3. How do sizers manage the size and alignment of their children?

11.2.4. Can I specify a minimum size for my sizer or its children?

11.2.5. How do sizers manage the border around each child?

11.3. Using the other sizer types

11.3.1. What’s a flex grid sizer?

11.3.2. What’s a grid bag sizer?

11.3.3. What’s a box sizer?

11.3.4. What’s a static box sizer?

11.4. Can I see a real-world example of sizers in action?

11.5. Summary

12. Manipulating basic graphical images

12.1. Working with images

12.1.1. How do I load images?

12.1.2. What can I do with an image?

12.1.3. How can I change cursors?

12.2. Dealing with device contexts

12.2.1. What is a device context, and how can I create one?

12.2.2. How do I draw to a device context?

12.2.3. How do I draw images to the context?

12.2.4. How can I draw text to the context?

12.3. Graphics manipulation

12.3.1. How do I manage the foreground drawing pen?

12.3.2. How do I manage the background drawing brush?

12.3.3. How can I manage logical and physical device coordinates?

12.3.4. What color names are predefined?

12.4. Summary


13. Building list controls and managing items

13.1. Building a list control

13.1.1. What is icon mode?

13.1.2. What is small icon mode?

13.1.3. What is list mode?

13.1.4. What is report mode?

13.1.5. How do I create a list control?

13.2. Managing items in a list

13.2.1. What is an image list and how do I add images to it?

13.2.2. How can I add and delete items from a list?

13.3. Responding to users

13.3.1. How can I respond to a user selection in a list?

13.3.2. How can I respond to a user selection in a column header?

13.4. Editing and sorting list controls

13.4.1. How can I edit a label?

13.4.2. How can I sort my list?

13.4.3. How can I learn more about list controls?

13.5. Creating a virtual list control

13.6. Summary

14. Coordinating the grid control

14.1. Creating your grid

14.1.1. How do I create a simple grid?

14.1.2. How do I create a grid with a grid table?

14.2. Working with your grid

14.2.1. How do I add and delete rows, columns, and cells?

14.2.2. How do I manage the row and column headers of a grid?

14.2.3. How can I manage the size of grid elements?

14.2.4. How can I manage which cells are selected or visible?

14.2.5. How do I change the color or font of a grid cell?

14.3. Custom renderers and editors

14.3.1. How do I use a custom cell renderer?

14.3.2. How do I edit a cell?

14.3.3. How do I use a custom cell editor?

14.4. Capturing user events

14.4.1. How can I capture user mouse selections?

14.4.2. How can I capture user keyboard navigation?

14.5. Summary

15. Climbing the tree control

15.1. Creating tree controls and adding items

15.1.1. How do I add a root?

15.1.2. How do I add more items to the tree?

15.1.3. How do I manage items?

15.2. What styles control the display of the tree control?

15.3. Sorting elements of a tree control

15.4. Controlling the image for each item

15.5. Navigating the tree programmatically

15.6. Managing the tree selection

15.7. Controlling which items are visible

15.8. Making a tree control user editable

15.9. Responding to other user events from a tree control

15.10. Using a tree list control

15.11. Summary

16. Incorporating HTML into your application

16.1. Displaying HTML

16.1.1. How can I display HTML in a wxPython window?

16.1.2. How can I display HTML from a file or URL?

16.2. Manipulating the HTML window

16.2.2. How can I change an HTML window programmatically?

16.2.3. How can I display the page title in a frame’s title bar?

16.2.4. How can I print an HTML page?

16.3. Extending the HTML window

16.3.1. How does the HTML parser work?

16.3.2. How can I add support for new tags?

16.3.3. How can I support other file formats?

16.4. Summary

17. The wxPython printing framework

17.1. How do I print in wxPython?

17.1.1. Understanding the printout lifecycle

17.1.2. Print framework in action

17.1.3. Working with wx.Printout methods

17.2. How do I display the print dialog?

17.2.1. Creating a print dialog

17.3. How do I display the page setup dialog?

17.3.1. Creating a page setup dialog

17.3.2. Working with page setup properties

17.4. How do I print something?

17.5. How can I perform a print preview?

17.6. Summary

18. Using other wxPython functionality

18.1. Putting objects on the clipboard

18.1.1. Getting data in the clipboard

18.1.2. Manipulating data in the clipboard

18.1.3. Retrieving text data from the clipboard

18.1.4. The clipboard in action

18.1.5. Passing other data formats

18.2. Being the source of a drag and drop

18.2.1. Dragging in action

18.3. Being the target of a drag and drop

18.3.1. Using your drop target

18.3.2. Dropping in action

18.4. Transferring custom objects

18.4.1. Transferring a custom data object

18.4.2. Retrieving a custom object

18.4.3. Transferring an object in multiple formats

18.5. Setting timed events using wx.Timer

18.5.1. Generating EVT_TIMER events

18.5.2. Learning other timer uses

18.6. Creating a multithreaded wxPython application

18.6.1. Working with the global function wx.CallAfter()

18.6.2. Managing thread communication with the queue object

18.6.3. Developing your own solution

18.7. Summary


What's inside

  • A tutorial for core wxPython features
  • A reference for wxPython classes and methods
  • Includes dozens of examples, including a full sketch application

About the authors

Noel Rappin is a senior software engineer at a large technology company, and has extensive Python experience. He has a Ph.D. from the Georgia Institute of Technology, where he studied educational software and user interface design. Noel co-authored the book Jython Essentials.

Robin Dunn, the creator and maintainer of wxPython, has been working in the software industry for 18 years on a wide variety of applications. He discovered both wxWindows and Python in 1995 while looking for a cross platform toolkit and has never (willingly) looked back. Robin was awarded the ActiveState Programmers' Choice Award at the 2002 O'Reilly Open Source Convention. Robin also worked for the Open Source Applications Foundation, improving wxPython for use in their flagship product, Chandler.

placing your order...

Don't refresh or navigate away from the page.
print book $49.95 pBook + PDF
Additional shipping charges may apply
Prints and ships within 3-5 days
wxPython in Action (print book) added to cart
continue shopping
go to cart

eBook $39.99 PDF only
wxPython in Action (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.

FREE domestic shipping on three or more pBooks