Using Wing with PyGTK

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 PyGTK and GTK+, an open source 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.


PyGTK is currently available for Linux/Unix, Windows, and Mac OS X (requires X11 Server). Like PyQt and unlike wxPython, PyGTK runs on the same (GTK-provided) widget implementations on all platforms. Themes can be used to approximate the look and behavior of widgets on the native OS. It is also possible to display native dialogs like the Windows file and print dialogs along side GTK windows. While PyGTK does not offer perfect native look and feel, its provides excellent write-once-works-anywhere capability even in very complex GUIs. Wing is itself written using PyGTK.

Other advantages of PyGTK include: (1) high quality anti-aliased text rendering, (2) powerful signal-based architecture that, among other things, allows subclassing C classes in Python, (3) multi-font text widget with embeddable sub-widgets, (4) model-view architecture for list and tree widgets, and (5) a rich collection of widgets and stock icons.

While Wing does not currently provide a GUI builder for PyGTK, 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 PyGTK:

  • Install Python and Wing. See the generic Quickstart Guide for installation instructions.
  • Install GTK and PyGTK. If you are on Linux, you may already have one or both installed, or you may be able to install them using your distribution's package manager. Otherwise, check out the gtk website and pygtk website.
  • 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 PyGTK, then select Project Properties from the Project menu and use the Python Executable field to select the correct Python version.
  • Add some files to your project, and set the main entry point with Set Main Debug File in the Debug menu.
  • Save your project to disk. Use a name ending in .wpr.
  • You should now be able to debug your PyGTK application from within Wing. If you see ImportErrors on the PyGTK modules, you will need to add Python Path in the Debug tab of Project Properties, accessed from the Project menu.

Auto-completion and Source Assistant

To obtain auto-completion options and call signature information in Wing Pro's Source Assistant, you may need to run a script that converts from PyGTK's defs files into Python interface files that Wing's source analyser can read. This is only necessary if you are working with PyGTK significantly different than version 2.7.4, because Wing ships with pre-built interface information for PyGTK 2.7.4. If you do need to build interface files, do so as follows:

  • Run as described within the script to produce a *.pi file for each *.so or *.pyd file in the PyGTK sources.
  • Copy these *.pi files into the installed copy of PyGTK, so they sit next to the compiled *.so or *.pyd extension module file that they describe.
  • Wing should now provide auto-completion and (in Wing Pro) Source Assistant information when you import gtk and type gtk. in the editor.

With newer PyGTK versions, it may be necessary to make modifications to the script to track changes in the nature of the source base.

Using a GUI Builder

Wing doesn't currently include a GUI builder for PyGTK but it can be used with other tools, such as glade.

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.

Details and Notes

  • Building GTK from sources can be a challenge. Wingware has developed some build support scripts which we can provide on request. We also have patches that allow GTK to be relocated after building on Linux/Unix.
  • Native look and feel on Windows is provided by the gtk-wimp theme. If you plan to deploy on Windows, you may wish to contact us to obtain our latest performance patches for GTK on Windows.

Unfortunately not all of our patches have been merged into the current GTK sources, although we have contributed patches in all cases so they can be retrieved from the source forge bug tracker as well.

Related Documents

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