8

TL;DR: Is there a library for declarative UI creation using GTK? Preferrably with Python support.


I'm a Python/Django developer, most of my experience about user interfaces is from the web, where declarative, loosely coupled UI designs are standard. Recently I've had to create a GUI app using Java/Swing for a school project and ended up using SwiXML to create declarative Swing layouts for the project.

I asked myself whether there are similar possibilities to use for Python. I'm not very fond of Java, so I won't start developing Swing applications. When looking for Python GUI Toolkits, I ended up concluding that the three main players in this field are GTK, QT and Wx.

Of those 3 I'd prefer GTK, but I could not find any way to create a declarative UI with GTK. From my experience with HTML and SwiXML, I find code based UI creation a huge mess and would prefer not having to do it that way. Declarative UI is much more flexible and more loosly coupled.

Is there a library for declarative UI creation using GTK? Preferrably with Python support.

If there isn't such a thing (which I assume, as I couldn't find anything), I might end up getting started with QT, even though I don't like the default look of it under Linux. (But maybe that's customizable too, in a way so that it looks similar to GTK.)

Danilo Bargen
  • 18,626
  • 15
  • 91
  • 127
  • 1
    http://www.clutter-project.org/ – kechap Dec 19 '11 at 13:00
  • Some time ago, Qt started to correctly mimic the GTK themes on Linux, too. So there is no "default look" to it anymore. Also, there is [Qt Quick](https://qt.nokia.com/qtquick/) for declarative Qt UIs. (adding this as a comment because the question was specifically aimed at GTK). – Tamás Szelei Dec 19 '11 at 13:10
  • @marcushatchenson wow, this looks rather neat! – Danilo Bargen Dec 19 '11 at 13:10
  • @TamásSzelei Thanks for the comment. I'm aware of the declarative Qt UIs, that's why I mentioned it in the first place. Is the "GTK imitation" default behavior or does it have to be enabled? Because for example Calibre looks very Qtish (and in my opinion ugly) on my Linux machine. – Danilo Bargen Dec 19 '11 at 13:14
  • 1
    It is the default. You can quickly try it out if you run qt creator and throw some widgets on a form. Calibre specifically implements some weird UI concepts (typical "designed by a programmer" look) and I agree that it's ugly. I wouldn't call it "Qt-ish", and again there is no default look for Qt. Maybe if you have KDE installed it will try to use that style? I only have gnome at the moment. Good examples of proper Qt UIs are VLC and Clementine. They look very native in both Linux and Windows. – Tamás Szelei Dec 19 '11 at 14:07
  • [Here's a quick demonstration](http://i.imgur.com/nWJtK.png). As you can see, it's not perfect, for example the comboboxes look different (although personally I think the GTK combox is uglier) – Tamás Szelei Dec 19 '11 at 14:08
  • Oh, I didn't realize VLC and Clementine are written using Qt. You convinced me that the look and feel is not an issue anymore :) Thanks. – Danilo Bargen Dec 19 '11 at 14:16

2 Answers2

14

I think what you're looking for is gtk.Builder. Basically, gtk.Builder objects can be used to load a .ui file that contains xml data that describes the widgets for the user interface and the callbacks to the events that should be exposed by the code. The .ui file can be created with glade so you don't even need to write the xml yourself.

jcollado
  • 39,419
  • 8
  • 102
  • 133
2

Look at enaml. Although there is no GTK toolkit, it is the only truly declarative framework for python that I'm aware of.

frmdstryr
  • 20,142
  • 3
  • 38
  • 32