PyQt4 and Python 3 - Display an image from URL -
i found code displaying image url. code doesn't work python 3.4. think urllib seperated 2 modules on python 3 urllib.request. can't convert code display on python 3.
from pyqt4.qtgui import qpixmap, qicon import urllib url = 'http://example.com/image.png' data = urllib.urlopen(url).read() pixmap = qpixmap() pixmap.loadfromdata(data) icon = qicon(pixmap)
so how can display image on python 3 , pyqt4? thanks.
try this:
import sys pyqt4 import qtgui import urllib.request class example(qtgui.qwidget): def __init__(self): super(example, self).__init__() self.initui() def initui(self): hbox = qtgui.qhboxlayout(self) url = 'http://www.google.com/images/srpr/logo1w.png' data = urllib.request.urlopen(url).read() image = qtgui.qimage() image.loadfromdata(data) lbl = qtgui.qlabel(self) lbl.setpixmap(qtgui.qpixmap(image)) hbox.addwidget(lbl) self.setlayout(hbox) self.show() def main(): app = qtgui.qapplication(sys.argv) ex = example() sys.exit(app.exec_()) if __name__ == '__main__': main()
Comments
Post a Comment