Hola_Mundo.py (creado con pyuic4):
Código
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'Hola_Mundo.ui' # # Created: Tue Jun 05 13:09:41 2012 # by: PyQt4 UI code generator 4.9.1 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: _fromUtf8 = lambda s: s class Ui_Formulario(object): def setupUi(self, Formulario): Formulario.setObjectName(_fromUtf8("Formulario")) Formulario.resize(400, 164) Formulario.setFrameShape(QtGui.QFrame.StyledPanel) Formulario.setFrameShadow(QtGui.QFrame.Raised) self.texto = QtGui.QLabel(Formulario) self.texto.setGeometry(QtCore.QRect(10, 20, 101, 16)) self.texto.setFrameShape(QtGui.QFrame.NoFrame) self.texto.setFrameShadow(QtGui.QFrame.Plain) self.texto.setObjectName(_fromUtf8("texto")) self.campoNombre = QtGui.QLineEdit(Formulario) self.campoNombre.setGeometry(QtCore.QRect(110, 20, 281, 20)) self.campoNombre.setObjectName(_fromUtf8("campoNombre")) self.botonHola = QtGui.QPushButton(Formulario) self.botonHola.setGeometry(QtCore.QRect(10, 50, 75, 23)) self.botonHola.setObjectName(_fromUtf8("botonHola")) self.campoSaludo = QtGui.QLineEdit(Formulario) self.campoSaludo.setEnabled(False) self.campoSaludo.setGeometry(QtCore.QRect(90, 50, 301, 20)) self.campoSaludo.setObjectName(_fromUtf8("campoSaludo")) self.retranslateUi(Formulario) QtCore.QObject.connect(self.botonHola, QtCore.SIGNAL(_fromUtf8("clicked()")), Formulario.saluda) QtCore.QMetaObject.connectSlotsByName(Formulario) def retranslateUi(self, Formulario): Formulario.setWindowTitle(QtGui.QApplication.translate("Formulario", "MI Primer programa con PyQT", None, QtGui.QApplication.UnicodeUTF8)) self.texto.setText(QtGui.QApplication.translate("Formulario", "Ingrese su nombre:", None, QtGui.QApplication.UnicodeUTF8)) self.botonHola.setText(QtGui.QApplication.translate("Formulario", "Hola", None, QtGui.QApplication.UnicodeUTF8))
Y finalmente el codigo de mi aplicacion app1.pyw es el siguiente:
Código
# -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui import sys from Hola_Mundo import Ui_Formulario class MyForm(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Formulario self.ui.setupUi(self) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = MyForm() myapp.show() sys.exit(app.exec_())
Pero al ejecutar me sale el siguiente error:
Código:
Traceback (most recent call last):
File "C:\py\pyqt\app1.pyw", line 16, in <module>
myapp = MyForm()
File "C:\py\pyqt\app1.pyw", line 12, in __init__
self.ui.setupUi(self.ui)
TypeError: unbound method setupUi() must be called with Ui_Formulario instance as first argument (got type instance instead)
Podrian decirme que estoy haciend mal por favor?
Saludos