How to display an image from web?
Question: I have written this simple script in python:

    
    
    import gtk
    
    window = gtk.Window()
    window.set_size_request(800, 700)
    
    window.show()
    gtk.main()
    

now I want to load in this window an image from web ( and not from my PC )
like this:

<http://www.dailygalaxy.com/photos/uncategorized/2007/05/05/planet_x.jpg>

How can I do that ?

P.S. I don't want download the image ! I just want load the image from the
URL.


Answer: This downloads the image from a url, but writes the data into a
[gtk.gdk.Pixbuf](http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html) instead
of to a file:

    
    
    import pygtk
    pygtk.require('2.0')
    import gtk
    import urllib2
    
    class MainWin:
    
        def destroy(self, widget, data=None):
            print "destroy signal occurred"
            gtk.main_quit()
    
        def __init__(self):
            self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
            self.window.connect("destroy", self.destroy)
            self.window.set_border_width(10)
            self.image=gtk.Image()
            response=urllib2.urlopen(
                'http://www.dailygalaxy.com/photos/uncategorized/2007/05/05/planet_x.jpg')
            loader=gtk.gdk.PixbufLoader()
            loader.write(response.read())
            loader.close()        
            self.image.set_from_pixbuf(loader.get_pixbuf())
            # This does the same thing, but by saving to a file
            # fname='/tmp/planet_x.jpg'
            # with open(fname,'w') as f:
            #     f.write(response.read())
            # self.image.set_from_file(fname)
            self.window.add(self.image)
            self.image.show()
            self.window.show()
    
        def main(self):
            gtk.main()
    
    if __name__ == "__main__":
        MainWin().main()
    

