Building enhanced visual GUIs on the Windows NT Platform with Pythonwin

Ryan Hughes



Python’s high runtime dynamic capabilities provide an ideal base platform to perform rapid development of graphical user interfaces. Ever since I ran across Python and Mark Hammond’s Pythonwin one of my big wishes was to be able to develop Windows NT applications in Python, that support the GUI features and current look and feel as seen in the major Windows software packages. So eventually I decided to try to find a solution for this.

1. Approach

Based on Mark Hammond’s Pythonwin a modified version of Pythonwin was created to support one of the leading third party MFC Visual C++ extension libraries. One of the main aims was to be able to program all features of a Windows application dynamically at runtime, without the dependency of having to create compiled resources, and needing to link them into Python dynamic link libraries (.pyd’s). At the C++ level support was added for creating resources for menus, form views and image lists out of Python tuples. This enables applications to quickly create all necessary GUI framework components for their display in Python, and it’s possible to take advantage of Python’s rapid speed of development for this area, too.

1.1. Supported Features

At the current stage of development support is available for many new and advanced features that are provided by the MFC extension library we chose. These include docking menu bars, docking windows, MDI alternatives for window management, etc. Furthermore several new dialog, tree and list controls, and a C++ backed dialog layout management, that provides fast window and control rearrangement when resizing a frame.

1.2. Availability

One disadvantage of choosing a commercial library was that we had to accept the fact, that due to licensing restrictions the interfaces to these extensions can’t be distributed free of charge. Third Party licenses are required for developers. Nevertheless I think these extensions for Pythonwin prove, that Python is a competitive language for developing up to date GUI interfaces for Windows. Once again Python together with Pythonwin is one of the only alternative languages besides C++ that has the flexibility to support these kinds of features.

Furthermore by being very dynamic at runtime Python will help to simplify adding web browser like features and dynamic forms functionality to MFC style applications. With the expanding acceptance of Internet browser interfaces by users, this is an expectation that will be necessary to be supported by future user interfaces of non web-based applications as well.

1.3. Credits

Without Mark Hammond’s Pythonwin for Visual C++ this naturally would never have been created, so a big thanks to Mark for developing such a great tool!

1.4. Copyright Notice

Pythonwin is Copyright Mark Hammond; Visual Python and Visual Python Edition is Copyright Ryan Hughes and Neuberger & Hughes GmbH; Python is Copyright Stichting Mathematisch Centrum, Amsterdam, The Netherlands; MFC, Visual C++, Windows NT are Trademarks of Microsoft Corp.

Figure 1: Pythonwin in action