# aspiring python developer needs help sorting out gtk2 vs gtk3

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 close merge delete

Sort by » oldest newest most voted

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.choose = self.builder.get_object("chooser_dialog");
self.bookStore = self.builder.get_object("bookstore");
self.bookView = self.builder.get_object("bookview");

self.builder.connect_signals(self)
self.window.show()
Gtk.main()

def on_window_destroy(self, widget, data=None):
Gtk.main_quit()

def on_open_menu_item_activate(self, widget, data=None):
self.choose.run()
self.choose.hide()

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]))
self.bookView.show()

def on_quit_menu_item_activate(self, widget, data=None):
Gtk.main_quit()

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



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 :-)

more

great places to start developing in GTK :

GNOME Developer Center

Migrating from GTK+ 2.x to GTK+ 3

more

## Stats

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

Seen: 2,086 times

Last updated: Feb 21 '12