Pygoo

Pygoo is a simple way to transform a Little Language widget specification into Tkinter widgets.

You can download or review the code at Google Code Hosting, Project Pygoo.

History of Pygoo

Awhile back I had to deal with a software system that used XML as its configuration file format. I don't like hand editing XML, so I usually use ElementTree to programmaticly build XML objects and then use those to generate the required XML code.

This works fine for small projects but it proved unwieldy in the case of these large configuration files I found myself working with, so I decided to create a simple LL to render XML via ElementTree objects from more concise form.

This Little Language had a simple macros and could handle any generic XML.

Later on, unrelated, I came across effbot's "Generating Tkinter User Interfaces from XML" where he demonstrates a recursive function that turned an XML specification of a Tkinter widget set into actual Tkinter widgets. The XML processing was of course handled by ElementTree objects, and in fact the function accepted such an object as input rather than text XML data.

I took this function and added processing for "grid" widget layout control, which allows you to use the Grid Layout Manager to arrange your widgets.

I also added namespace support in the form of a dictionary that you pass in to the function. Any widget that you give a "name" attribute to will appear in this namespace dictionary keyed under that name. This allows you to use these widgets in your code without having to dig them out of the parent widgets' children attributes.

I used this function in a couple of projects to simplify GUI creation, but as soon as the GUIs became too large (too many subwidgets, etc.) the XML specs became almost as unwieldy as just programmaticly building the widgets would have been.

So one day, I had the bright idea to plug these two pieces of code together.

I took the ElementTree object output of the XML building code and, instead of writing it to a file, passed it to the widget building function and, presto, there was a live new widget set.

I cleaned up the language a bit, and added support for binding widgets to callback functions in the namespace dict, and pulled everything together in one module, and Pygoo was created.