Some suggestion for a GUI kit evolved on Perl

Donn Cave donn at
Wed Apr 5 23:35:33 CEST 2000

Quoth "Makhno" <mak at>:
| 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:
| Orchard::NewOrcWindow
| (
|     title=>"Test"
| )->Add
| (
|     OrcVGroup
|     (
|         OrcButton,
|         $label=OrcLabel
|     )
| )->Show;
| 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.

(Looks to me like the button and label are arranged vertically?)

| 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
| equivalent of:
| window=Orchard.NewOrcWindow(title="Test")
| button=OrcButton
| label=Label
| vgroup=OrcVGroup
| window.add(vgroup)
| vgroup.add(button)
| vgroup.add(label)
| window.Show
| 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.
| Orchard.NewOrcWindow(title=Text).Add(OrcVGroup(...
| 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
| creating Orchard!
| 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?

I hope I'm not missing the point here, but I'm not sure you can't
use white space.  For example, following is legal Python:

label = OrcLabel
    title = "Test"

The "label" variable has to be assigned outside the function call,
that's just the way it is.  Other than that, we're looking at a
couple of changes around the parentheses.  I changed "Show" to "Show()",
assuming you don't mean to return the bound function but rather the
result of its execution.

If it does the same thing as the Perl example, it's not all that different
in appearance.

	Donn Cave, donn at

More information about the Python-list mailing list