FORM PRINCIPAL:
Código Python:
Ver original
import sys import calculo 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(355, 118) self.Sumar = QtGui.QPushButton(Dialog) self.Sumar.setGeometry(QtCore.QRect(140, 30, 75, 23)) self.Sumar.setObjectName(_fromUtf8("Sumar")) self.labelInfo = QtGui.QLabel(Dialog) self.labelInfo.setGeometry(QtCore.QRect(160, 80, 141, 16)) self.labelInfo.setText(_fromUtf8("")) self.labelInfo.setObjectName(_fromUtf8("labelInfo")) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): Dialog.setWindowTitle(_translate("Dialog", "Dialog", None)) self.Sumar.setText(_translate("Dialog", "Sumar", None)) class suma(QtGui.QDialog): def __init__(self,parent=None): QtGui.QWidget.__init__(self,parent) self.ui=Ui_Dialog() self.ui.setupUi(self) self.ui.Sumar.clicked.connect(self.sumar) def sumar(self): ''' INSTANCIO EL FORM QUE HACE EL CACULO ''' self.ui.llamada=calculo.operacion() self.ui.llamada.show() self.ui.labelInfo.setText(self.ui.llamada.cadenacon) ##NO CAMBIA EL VALOR## if __name__=="__main__": app=QtGui.QApplication(sys.argv) myapp = suma() myapp.show() sys.exit(app.exec_())
FORM QUE SUMA Y NO DEVUELVE EL CONTADOR
Código Python:
Ver original
import sys 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(408, 200) self.lineEdit = QtGui.QLineEdit(Dialog) self.lineEdit.setGeometry(QtCore.QRect(140, 20, 113, 20)) self.lineEdit.setObjectName(_fromUtf8("lineEdit")) self.lineEdit_2 = QtGui.QLineEdit(Dialog) self.lineEdit_2.setGeometry(QtCore.QRect(140, 60, 113, 20)) self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2")) self.Calcular = QtGui.QPushButton(Dialog) self.Calcular.setGeometry(QtCore.QRect(160, 110, 75, 23)) self.Calcular.setObjectName(_fromUtf8("Calcular")) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): Dialog.setWindowTitle(_translate("Dialog", "Dialog", None)) self.Calcular.setText(_translate("Dialog", "Calcula!", None)) class operacion(QtGui.QDialog): def __init__(self,parent=None): QtGui.QWidget.__init__(self,parent) self.ui=Ui_Dialog() self.ui.setupUi(self) self.ui.Calcular.clicked.connect(self.calcular) self.con=0 self.cadenacon='' def calcular(self): '''METODO QUE SUMA Y DEVUELVE EL RESULTADO''' self.con+=1 self.cadenacon=str(self.con) a=int(self.ui.lineEdit.text()) b=int(self.ui.lineEdit_2.text()) oper=a+b self.resul=str(oper) print("Suma :",self.resul) print("N° de Suma ",self.cadenacon) if __name__=="__main__": app=QtGui.QApplication(sys.argv) myapp = operacion() myapp.show() sys.exit(app.exec_())
Presumo que el error debe estar en esta linea del Form principal:
Código Python:
Ver original
self.ui.llamada=calculo.operacion() self.ui.llamada.show() self.ui.labelInfo.setText(self.ui.llamada.cadenacon) ##NO CAMBIA EL VALOR##
Ya que si hago un print de self.cadenacon, desde el modulo que se invoca, imprime el conteo sin detalles, no entiendo por que no se pasa el valor al label, de igual forma sus consejos me serían de muchisíma utilidad, gracias de antemano por la ayuda que me puedan brindar ! .