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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

GTK3 is backward compatible ? Ok good news, I'll do that them. Thanks
"Mostly" source-level backward compatible, to be honest.
@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! :)
But, if you've written pyGTK2 with glade, and you cannot use glade with pygobject Gtk3 unless you convert to an entirely different format, then it isn't really "backward compatible", isn't it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.