Using Wing with wxPython

Index of All Documentation » How-Tos » How-Tos for GUI Development »

Wing is a Python IDE that can be used to develop, test, and debug Python code written for the wxPython cross-platform GUI development toolkit. Two versions of Wing are appropriate for use with this document: Wing Pro is the full-featured Python IDE for professional programmers, and Wing Personal is a free alternative with reduced feature set.

If you do not already have Wing installed, download it now.

To get started using Wing, refer to the tutorial in the Help menu in Wing or the Quickstart Guide.


wxPython is a good choice for GUI developers. It currently available for MS Windows, Linux, Unix, and Mac OS X and provides native look and feel on each of these platforms.

While Wing does not provide a GUI builder for wxPython, it does provide the most advanced capabilities available for the Python programming language, and it can be used with other available GUI builders, as described below.

Installation and Configuration

Take the following steps to set up and configure Wing for use with wxPython:

  • Install Python and Wing. You will need a specific version of Python depending on the version of wxPython you plan to use. Check the wxPython Getting Started Wiki when in doubt. See the generic Quickstart Guide for installation instructions.
  • Install wxPython. See the wxPython's website Getting Started Wiki for installation instructions. Note that you need to install the version of wxPython to match your Python version, as indicated on the download page.
  • Start Wing from the Start menu on Windows, the Finder or OS X, or by typing wing6.0 on the command line on Linux other Posix systems. Once Wing has started, you may want to switch to reading this How-To from the Help menu. This will add links to the functionality of the application.
  • Select Show Python Environment from the Source menu and if the Python version reported there doesn't match the one you're using with wxPython, then select Project Properties from the Project menu and use the Python Executable field to select the correct Python version.
  • Open the wxPython demo into Wing. This may be located within your Python installation at site-packages/wx/demo/, or Lib/site-packages/wx/demo/, or c:\Program Files\wxPython2.6 Docs and Demos\demo, or similar location. On Linux it may be part of a separate wx examples package, for example on Ubuntu 6.06 LTS the demo is in the package wx2.6-examples, is installed in /usr/share/doc/wx2.6-examples/examples/wxPython, and some files in this directory need to be gunzip``ed before the demo will work. Once you've opened ``, select Add Current File from the Project menu. If you can't find but have other wxPython code that works, you can also just use that. However, the rest of this document assumes you're using so you will have to adapt the instructions.
  • Set as main entry point for debugging using the Set Main Debug File item in the Debug menu.
  • Save your project to disk. Use a name ending in .wpr.

Test Driving the Debugger

Now you're ready to try out the debugger. To do this:

Start debugging with the Start / Continue item in the Debug menu. Uncheck the Show this dialog before each run checkbox at the bottom of the dialog that appears and select OK.

The demo application will start up. If its main window doesn't come to front, bring it to front from your task bar or window manager. Try out the various demos from the tree on the left of the wxPython demo app.

Important: In earlier wxPython 2.6 versions, a change to the demo code breaks all debuggers by not setting the co_filename attribute on code objects correctly. To fix this, change the line that reads description = self.modules[modID][2] around line 804 in demo\ to instead read description = self.modules[modID][3] -- Wing will not stop at breakpoints until this is done.

Next open (located in the same directory as into Wing. Set a breakpoint on the first line of runTest() by clicking on the dark grey left margin. Go into the running demo app and select More Dialogs / ImageBrowser. Wing will stop on your breakpoint.

Select Stack Data from the Tools menu. Look around the stack in the popup at the top of the window and the locals and globals shown below that for the selected stack frame. You may see some sluggishness (a few seconds) in displaying values because of the widespread use of from wx import * in wxPython code, which imports a huge number of symbols into the globals name space. This depends on the speed of your machine.

Select Debug Probe (Wing Pro only) from the Tools menu. This is an interactive command prompt that lets you type expressions or even change values in the context of the stack frame that is selected on the Debugger window when your program is paused or stopped at an exception. It is a very powerful debugging tool.

Also take a look at these tools available from the Tools menu:

  • I/O -- displays debug process output and processes keyboard input to the debug process, if any
  • Exceptions -- displays exceptions that occur in the debug process
  • Modules (Wing Pro only) -- browses data for all modules in sys.modules
  • Watch (Wing Pro only) -- watches values selected from other value views (by right-clicking and selecting one of the Watch items) and allows entering expressions to evaluate in the current stack frame

Using a GUI Builder

Wing doesn't currently include a GUI builder for wxPython but it can be used with other tools, such as Boa Constructor, which does provide a GUI builder but doesn't have the raw power of Wing's debugger and source browser.

To use an external GUI builder, configure Wing to automatically reload files that are altered by the GUI builder. This is done in Preferences in the Files Reloading area.

Then you can run Wing and your GUI builder at the same time, working with both in an almost seamless manner.

A Caveat: Because Python lends itself so well to writing data-driven code, you may want to reconsider using a GUI builder for some tasks. In many cases, Python's introspection features make it possible to write generic GUI code that you can use to build user interfaces on the fly based on models of your data and your application. This can be much more efficient than using a GUI builder to craft individual menus and dialogs by hand. In general hand-coded GUIs also tend to be more maintainable.

Related Documents

Wing provides many other options and tools. For more information: