PASO 1: Crear la interfaz gráfica en QT y convertir de .ui a .py.
Nota: El botón REGRESAR no va a tener una funcionalidad en este ejercicio, en otra entrada servirá para explicar subventanas.
se hace la conversión:
Se obtiene el siguiente código:
foto.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'foto.ui' # # Created by: PyQt4 UI code generator 4.11.4 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromUtf8(s): return s try: _encoding = QtGui.QApplication.UnicodeUTF8 def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig, _encoding) except AttributeError: def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig) class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName(_fromUtf8("Dialog")) Dialog.resize(543, 372) self.webView = QtWebKit.QWebView(Dialog) self.webView.setGeometry(QtCore.QRect(60, 40, 471, 291)) self.webView.setUrl(QtCore.QUrl(_fromUtf8("about:blank"))) self.webView.setObjectName(_fromUtf8("webView")) self.pushButton = QtGui.QPushButton(Dialog) self.pushButton.setGeometry(QtCore.QRect(60, 340, 75, 23)) self.pushButton.setObjectName(_fromUtf8("pushButton")) self.lineEdit = QtGui.QLineEdit(Dialog) self.lineEdit.setGeometry(QtCore.QRect(60, 10, 471, 20)) self.lineEdit.setObjectName(_fromUtf8("lineEdit")) self.label = QtGui.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(10, 10, 51, 20)) self.label.setObjectName(_fromUtf8("label")) self.pushButton_2 = QtGui.QPushButton(Dialog) self.pushButton_2.setGeometry(QtCore.QRect(460, 340, 75, 23)) self.pushButton_2.setObjectName(_fromUtf8("pushButton_2")) self.pushButton_3 = QtGui.QPushButton(Dialog) self.pushButton_3.setGeometry(QtCore.QRect(370, 340, 75, 23)) self.pushButton_3.setObjectName(_fromUtf8("pushButton_3")) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): Dialog.setWindowTitle(_translate("Dialog", "Dialog", None)) self.pushButton.setText(_translate("Dialog", "MOSTRAR", None)) self.label.setText(_translate("Dialog", "ENLACE:", None)) self.pushButton_2.setText(_translate("Dialog", "SALIR", None)) self.pushButton_3.setText(_translate("Dialog", "REGRESAR", None)) from PyQt4 import QtWebKit |
PASO 2: Elegir una imagen, guardar su dirección url (esta es la mía)
PASO 3: Crear el archivo ejecutable.
codigo_foto.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import sys from foto import * from PyQt4.QtGui import QApplication from PyQt4.QtCore import QUrl from PyQt4.QtWebKit import QWebView class showmap(QtGui.QDialog): def __init__(self,parent=None): QtGui.QWidget.__init__(self,parent) QWebView.__init__(self) self.ui = Ui_Dialog() self.ui.setupUi(self) QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'),self.mostrar) QtCore.QObject.connect(self.ui.pushButton_3, QtCore.SIGNAL('clicked()'),self.regresar) QtCore.QObject.connect(self.ui.pushButton_2, QtCore.SIGNAL('clicked()'),self.salir) def mostrar(self): imagen=self.ui.lineEdit.text() self.ui.webView.load(QUrl(imagen)) def regresar(self): self.close() def salir(self): self.close() if __name__== "__main__": app=QtGui.QApplication(sys.argv) myapp = showmap() myapp.show() sys.exit(app.exec_()) |
Al ejecutar e ingresar la dirección URL esto es lo que se obtiene:
Es todo muchas gracias. Si tienen alguna duda estaré atento.
No hay comentarios.:
Publicar un comentario