Ask Your Question

aspiring python developer needs help sorting out gtk2 vs gtk3

asked 2011-12-31 06:36:57 -0500

ryran gravatar image

updated 2012-02-21 13:15:15 -0500

So I've been learning python and over the last couple days playing with Glade3 on my Fedora16 box. Every time I try to run one of my python [or even C] apps (which use gtkbuilder to load a glade xml file), I get a warning like this:

cannot create instance of abstract (non-instantiatable) type 'GtkBox'

Thanks to google I've come to a pseudo-understanding of the situation. Glade v3.10 dropped support for GTK versions less than 3 and apparently GtkVBox, GtkHBox, GtkVButtonBox, & GtkHButtonBox from GTK2 were replaced with GtkBox & GtkButtonBox (w/properties to specify horizontal/vertical) in GTK3.

Solution? Apparently one can use the older Glade 3.8 or manually edit the 3.10-produced files.

But what about running my apps with GTK3? I don't even know where to start. All the examples I've seen for python are for GTK2, I think. Starting out with python GUI programming, with linux being the intended platform, what should I focus my energy on? I believe any system that has GNOME3 has GTK3, right? I assume all systems that have GTK3 will also have GTK2, right? For relatively simple programs is there any benefit to using GTK3 (and whatever the python bindings for it are)?

So really, I'm just looking for a little guidance on this whole GTK2 vs GTK3 thing. Thanks for reading.

EDIT: In the end I went with installing Glade 3.8 for now and sticking to GTK2, I guess. My app works beautifully, so for now, I'm happy with that route.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2011-12-31 10:09:49 -0500

Bikehead gravatar image

I'm on the same journey you are trying to learn Glade on python and I ran into the same issues you did. I'm still not at full understanding by any means, but perhaps my discoveries can help you.

First, every tutorial, including those at the glade home page seem to be out of date. They all say to "import gtk", but this seems to be old even though it is packaged with F16. If you use this gtk then you will get the error from gtkbuilder. Instead I found that the following code works and doesn't cause an error:

import gi
gi.require_version("Gtk", "3.0")
# from gi.repository import Gtk,GdkPixbuf,GObject,Pango,Gdk
from gi.repository import Gtk

# import gtk -- this doesn't work

class CommanderApp(object):       
    def __init__(self):
        self.builder = Gtk.Builder()

        self.window = self.builder.get_object("window")
        self.about = self.builder.get_object("about_dialog");
        self.choose = self.builder.get_object("chooser_dialog");
        self.bookStore = self.builder.get_object("bookstore");
        self.bookView = self.builder.get_object("bookview");


    def on_window_destroy(self, widget, data=None):

    def on_open_menu_item_activate(self, widget, data=None):

        self.curDir = self.choose.get_files();
        for b, v in listBooks([x.get_path() for x in self.curDir]).items():
            self.bookStore.append((v[TITLE], v[CREATOR]))

    def on_quit_menu_item_activate(self, widget, data=None):

    def on_delete_menu_item_activate(self, widget, data=None):

    def on_about_menu_item_activate(self, widget, data=None):

Obviously, this is a fragment from my program, but hopefully it give you an idea. I've been using Glade3, eclipse PyDev and python with success. My UI has a simple GtkTreeView view with a GtkListStore.

One other issue though, in order to get columns in a tree view I had to add GtkTreeColumn items with GtkCellRendererText children. However, I could not find these two elements in the glade UI builder. Furthermore when I selected my GtkTreeView element and right-click->Edit..., glade crashes. I eventually edited the glade file by hand to add the elements. After that when I open the file in Glade then I see these elements in the widget window and the preview (the edit sequence still crashes though).

Anyway that is where I'm at. I have my UI displaying and responding, so I'm calling it a success :-)

edit flag offensive delete link more

answered 2011-12-31 06:52:53 -0500

hhlp gravatar image

updated 2011-12-31 07:14:43 -0500

edit flag offensive delete link more

Question Tools



Asked: 2011-12-31 06:36:57 -0500

Seen: 2,086 times

Last updated: Feb 21 '12