Pythonic gui format?

Georg Brandl g.brandl-nospam at gmx.net
Mon Feb 13 15:50:52 EST 2006


Gregory Petrosyan wrote:
> Buenos dias, amigos!
> I have to write  _simple_  gui library, for embedding into game. My
> first attempt was to use XML: isn't it cute to describe ui in such a
> way:
> 
> <window>
>     <title>Hello World!</title>
>     <image text="nice picture here" pos=... src=... />
>     <text opts=...>
>         (some text here)
>     </text>
>     <list>
>         <item>first element</item>
>         <item>second one...</item>
>     </list>
>     <button action=... text="Click Me!" />
> </window>

One could imagine to model this with Python, like this:

class FooDlg(Window):
    title = "Hello World!"
    size = (400, 300)

    class WelcomeImg(Image):
        filename = "..."
        pos = (0, 0)

    class Box(Frame):
        text = "My Controls"

        class NameLbl(Label):
            text = "Name:"

        class NameField(TextBox):
            length = 100
            pos = ...
            def onClick(self):
                 MessageBox(self.text)

        class TestList(ListBox):
            items = ['First', 'Second']

_Slight_ misuse of "class" though...

Georg



More information about the Python-list mailing list