Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing an app on Ubuntu 12.04 with Python and GTK 3. The problem I have is that I can't figure out how I should do to show a Gtk.Image in my app with an image file from the web.

This is as far as I have come:

from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
import urllib2

url = ''
response = urllib2.urlopen(url)
image = Gtk.Image()

I think everything is correct except the last line.

share|improve this question
up vote 2 down vote accepted

According to the docs, new_from_stream() needs a Gio.InputStream and Gio.Cancellable as arguments.

You could also save the image on disk and remove when needed. Here is a very basic example:

import os
import urllib2
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf

def quit_event(widget, event):

imgname = '1338.jpg'
url = ''+imgname
response = urllib2.urlopen(url)
with open(imgname, 'wb') as img:

image = Gtk.Image()
pb = Pixbuf.new_from_file(imgname)

window = Gtk.Window()
window.connect('delete-event', quit_event)

You should write to a better location though, maybe /tmp or a user-specified dir.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.