2

I'd like to create a graphical interface in python2 with GTK+.

For now I'm using gobject-introspection to use GTK3 but I'd like, if possible, to be compatible with GTK2 as well.

#!/usr/bin/python2
try:
    from gi.repository import Gtk
except:
    try:
        import gtk as Gtk
    except:
        print("You need GTK")

I was using a Grid for my window but it seems Gtk.Grid doesn't exist in GTK2. On the other hand Gtk.Table exists in both version.

Is it worth the try to make an app compatible for both version of GTK (and how ?) or I'll have to write almost twice more code ?

Thanks

Martin Trigaux
  • 5,311
  • 9
  • 45
  • 58

1 Answers1

2

Substantially the choice boils down to:

  1. Write for GTK2 directly (GTK3 is backward compatible)
  2. Write alternate implementations of parts of your UI for those widgets that are not available in GTK2.

In the second case, if you use good separation between your interface and your logic you won't need to write "twice as much" code, just reimplementing parts of the UI.

mac
  • 42,153
  • 26
  • 121
  • 131
  • 1
    GTK3 is backward compatible ? Ok good news, I'll do that them. Thanks – Martin Trigaux Dec 02 '11 at 11:25
  • "Mostly" source-level backward compatible, to be honest. – rodrigo Dec 02 '11 at 11:30
  • 1
    @MartinTrigaux By "backward compatible" I mean that the widgets with the same name works the same, so if you have code written for GTK2 it should work on GTK3 too. Hope this is what you need! :) – mac Dec 02 '11 at 11:31
  • But, if you've written pyGTK2 with glade, and you cannot [use glade with pygobject Gtk3](http://stackoverflow.com/questions/5984679/use-glade-with-pygobject-gtk3/24450153#24450153) unless you convert to an entirely different format, then it isn't really "backward compatible", isn't it? – sdaau Jul 01 '14 at 04:47