我正在 Ubuntu 12.04 上使用 Python 和 GTK 3 编写一个应用程序。我遇到的问题是我不知道应该如何使用来自网络的图像文件在我的应用程序中显示 Gtk.Image。
据我所知:
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
import urllib2
url = 'http://lolcat.com/images/lolcats/1338.jpg'
response = urllib2.urlopen(url)
image = Gtk.Image()
image.set_from_pixbuf(Pixbuf.new_from_stream(response))
我认为除了最后一行之外,一切都是正确的。
这会起作用;
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
from gi.repository import Gio
import urllib
url = 'http://lolcat.com/images/lolcats/1338.jpg'
response = urllib.request.urlopen(url)
input_stream = Gio.MemoryInputStream.new_from_data(response.read(), None)
pixbuf = Pixbuf.new_from_stream(input_stream, None)
image = Gtk.Image()
image.set_from_pixbuf(pixbuf)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)