Thursday, June 10, 2010

PyGI in Maverick

PyGI is now available in Maverick, you can install it with the following:

$ apt-get install python-gi gir1.0-gtk-2.0

and then write applications like this:

from gi.repository import Gtk

def destroy_cb(widget):
    Gtk.main_quit()

w = Gtk.Window()
w.connect('destroy', destroy_cb)

l = Gtk.Label()
l.set_text("Hello World!")
w.add(l)

w.show_all()
Gtk.main()


Have fun!

EDIT: Updated to note you need to install the GI package for the module you are using.

5 comments:

Promotux SNC said...

Not working for me

>>> from gi.repository import Gtk
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name Gtk

i can import gi and gi.repository

Tomeu Vizoso said...

@Promotux SNC:

You need to install gir1.0-gtk-2.0 as well.

Basically, you need the typelib for every library you want to call from python.

Dzhelil said...

Are you planning create a PPA so that we can install it on Ubuntu 10.04 as well?

Robert Ancell said...

@Dzhelil, no because there are too many things it depends on that would also need updating.

Alex Rodenberg said...

had to install gir1.2-gtk-3.0 and gir1.2-webkit-3.0