Some suggestion for a GUI kit evolved on Perl
mak at imakhno.freeserve.co.uk
Wed Apr 5 22:08:23 CEST 2000
I have written a GUI kit called Orchard. It is essentially a code library
with c-like functions which when called correctly will create windows,
buttons and other controls. I have had great success writing an interface
for this with Perl, and now I'm about to attempt a Python module.
One of the main points of Orchard is to keep the GUI-creation code as quick
and as neat as possible. Because Perl ignores whitespace, I have designed
the module in such a way so that the user can take advantage of this and use
whitespace indicate GUI structure. For example, the following code creates a
window with a button and a label in it:
As you can see, the window consists of a button and a label arranged
horizontally. A ref is kept to the label so it can be changed in later code,
and the window's Add() method returns a ref to the window so that Show() can
be called on it.
The problem I'm having is that Python has reserved whitespace (to indicate
program scope). Having looked at the Tk modules, I see it doing the
The problem is that this code stores references to everything (There's often
no need to keep references to buttons, it's looked after internally), it's
not as easy to read, and is easily complicated by GUI additions.
An alternative would be to use the style I've used with Perl; creating GUI
elements in the contructors of other GUI elements.
But without whitespace to help separate the elements I end up with a long
line that looks even worse than before. Separating the long line to several
smaller lines doesn't help readablity either (it just ends up all wrapped
round rather than structured). And the line has to be split up when I want
to keep a reference to the element anyway.
This complication is precisely the sort of thing I wished to avoid when
Does anybody have any advice as to how I could 'structure' Python code to
make neat, extendable GUI code? Essentially it comes down to what I can use
to indicate GUI structure. I can't use whitespace, so what can I use?
(The Library and Perl interface are located here:
More information about the Python-list