When I run the code a MainWindow appears in which there are two radioButtons, if I press either of the two, a container widget will be added and displayed in the main window, in it there will be several objects of which I care about the present labels , which will have a definite text, to re-press any of the radioButton a new text should appear on the labels however that is not what is happening, what happens is that the previous text is preserved and the new one is superimposed , that is, the texts are overlapping and the final result is a text incomprehensible to the user. How can I get the new text displayed by deleting the previous one, that's my problem.
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import ui_adap1stubnew12
class stub1(QMainWindow,ui_adap1stubnew12.Ui_adap1s):
def __init__(self, parent=None):
QWidget.__init__(self,parent)
self.setupUi(self)
self.i=False
self.band1=False
self.band2=False
self.connect(self.radioboton1, SIGNAL("clicked()"),self.llamarimpedancia)
self.connect(self.radioboton2, SIGNAL("clicked()"),self.llamaradmitancia)
def llamarimpedancia(self):
if self.i==False :
print(self.i)
self.band1=True
self.myapp3=self.contenido(self.grupo)
self.myapp3.show()
self.i=True
elif self.band2==True :
print(self.i)
self.band2=False
self.band1=True
self.myapp3=self.contenido(self.grupo)
self.myapp3.show()
else:
print(self.i)
self.band1=True
self.myapp3=self.contenido(self.grupo)
self.myapp3.show()#sin este comando no es mostrado en la ventana el nuevo widget
def llamaradmitancia(self):
if self.i==False :
print(self.i)
self.band2=True
self.myapp3=self.contenido(self.grupo)
self.myapp3.show()
self.i=True
elif self.band1==True :
print(self.i)
self.band1=False
self.band2=True
self.myapp3=self.contenido(self.grupo)
self.myapp3.show()
else:
print(self.i)
self.band2=True
self.myapp3=self.contenido(self.grupo)
self.myapp3.show()#sin este comando no es mostrado en la ventana el nuevo widget
def contenido(self, parent):
self.frame8 = QFrame(parent)
self.frame8.setGeometry(QRect(11,110,214,374))
#self.widget.setObjectName(_fromUtf8("widget"))
self.verticalLayout_5 = QVBoxLayout(self.frame8)
#self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5"))
spacerItem2 = QSpacerItem(20, 18, QSizePolicy.Minimum,QSizePolicy.Expanding)
self.verticalLayout_5.addItem(spacerItem2)
self.verticalLayout_2 = QVBoxLayout()
#self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.horizontalLayout_9 = QHBoxLayout()
#self.horizontalLayout_9.setObjectName(_fromUtf8("horizontalLayout_9"))
spacerItem3 = QSpacerItem(40, 20, QSizePolicy.Expanding,QSizePolicy.Minimum)
self.horizontalLayout_9.addItem(spacerItem3)
self.etiqueta2 = QLabel(self.frame8)
self.etiqueta2.setScaledContents(False)
self.etiqueta2.setWordWrap(False)
#self.etiqueta2.setObjectName(_fromUtf8("etiqueta2"))
self.horizontalLayout_9.addWidget(self.etiqueta2)
spacerItem4 = QSpacerItem(40, 20, QSizePolicy.Expanding,QSizePolicy.Minimum)
self.horizontalLayout_9.addItem(spacerItem4)
self.verticalLayout_2.addLayout(self.horizontalLayout_9)
self.horizontalLayout_3 = QHBoxLayout()
#self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
self.etiqueta3 = QLabel(self.frame8)
#self.etiqueta3.setObjectName(_fromUtf8("etiqueta3"))
self.horizontalLayout_3.addWidget(self.etiqueta3)
self.lineEdit1 = QLineEdit(self.frame8)
self.lineEdit1.setMaximumSize(QSize(90, 16777215))
#self.lineEdit1.setObjectName(_fromUtf8("lineEdit1"))
self.horizontalLayout_3.addWidget(self.lineEdit1)
self.etiqueta4 = QLabel(self.frame8)
#self.etiqueta4.setObjectName(_fromUtf8("etiqueta4"))
self.horizontalLayout_3.addWidget(self.etiqueta4)
self.verticalLayout_2.addLayout(self.horizontalLayout_3)
self.horizontalLayout_4 = QHBoxLayout()
#self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
self.etiqueta5 = QLabel(self.frame8)
#self.etiqueta5.setObjectName(_fromUtf8("etiqueta5"))
self.horizontalLayout_4.addWidget(self.etiqueta5)
self.lineEdit2 = QLineEdit(self.frame8)
self.lineEdit2.setMaximumSize(QSize(90, 16777215))
#self.lineEdit2.setObjectName(_fromUtf8("lineEdit2"))
self.horizontalLayout_4.addWidget(self.lineEdit2)
self.etiqueta6 = QLabel(self.frame8)
#self.etiqueta6.setObjectName(_fromUtf8("etiqueta6"))
self.horizontalLayout_4.addWidget(self.etiqueta6)
self.verticalLayout_2.addLayout(self.horizontalLayout_4)
self.verticalLayout_5.addLayout(self.verticalLayout_2)
spacerItem5 = QSpacerItem(20, 13, QSizePolicy.Minimum,QSizePolicy.Expanding)
self.verticalLayout_5.addItem(spacerItem5)
self.verticalLayout_3 = QVBoxLayout()
#self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
self.horizontalLayout_10 = QHBoxLayout()
#self.horizontalLayout_10.setObjectName(_fromUtf8("horizontalLayout_10"))
spacerItem6 = QSpacerItem(40, 20, QSizePolicy.Expanding,QSizePolicy.Minimum)
self.horizontalLayout_10.addItem(spacerItem6)
self.etiqueta7 = QLabel(self.frame8)
#self.etiqueta7.setObjectName(_fromUtf8("etiqueta7"))
self.horizontalLayout_10.addWidget(self.etiqueta7)
spacerItem7 = QSpacerItem(40, 20, QSizePolicy.Expanding,QSizePolicy.Minimum)
self.horizontalLayout_10.addItem(spacerItem7)
self.verticalLayout_3.addLayout(self.horizontalLayout_10)
self.horizontalLayout_5 = QHBoxLayout()
#self.horizontalLayout_5.setObjectName(_fromUtf8("horizontalLayout_5"))
self.etiqueta8 = QLabel(self.frame8)
#self.etiqueta8.setObjectName(_fromUtf8("etiqueta8"))
self.horizontalLayout_5.addWidget(self.etiqueta8)
self.lineEdit3 = QLineEdit(self.frame8)
self.lineEdit3.setMaximumSize(QSize(90, 16777215))
#self.lineEdit3.setObjectName(_fromUtf8("lineEdit3"))
self.horizontalLayout_5.addWidget(self.lineEdit3)
self.etiqueta9 = QLabel(self.frame8)
#self.etiqueta9.setObjectName(_fromUtf8("etiqueta9"))
self.horizontalLayout_5.addWidget(self.etiqueta9)
self.verticalLayout_3.addLayout(self.horizontalLayout_5)
self.horizontalLayout_6 = QHBoxLayout()
#self.horizontalLayout_6.setObjectName(_fromUtf8("horizontalLayout_6"))
self.etiqueta10 = QLabel(self.frame8)
#self.etiqueta10.setObjectName(_fromUtf8("etiqueta10"))
self.horizontalLayout_6.addWidget(self.etiqueta10)
self.lineEdit4 = QLineEdit(self.frame8)
self.lineEdit4.setMaximumSize(QSize(90, 16777215))
#self.lineEdit4.setObjectName(_fromUtf8("lineEdit4"))
self.horizontalLayout_6.addWidget(self.lineEdit4)
self.etiqueta11 = QLabel(self.frame8)
#self.etiqueta11.setObjectName(_fromUtf8("etiqueta11"))
self.horizontalLayout_6.addWidget(self.etiqueta11)
self.verticalLayout_3.addLayout(self.horizontalLayout_6)
self.horizontalLayout_7 = QHBoxLayout()
#self.horizontalLayout_7.setObjectName(_fromUtf8("horizontalLayout_7"))
self.etiqueta12 = QLabel(self.frame8)
#self.etiqueta12.setObjectName(_fromUtf8("etiqueta12"))
self.horizontalLayout_7.addWidget(self.etiqueta12)
self.lineEdit5 = QLineEdit(self.frame8)
self.lineEdit5.setMaximumSize(QSize(90, 16777215))
#self.lineEdit5.setObjectName(_fromUtf8("lineEdit5"))
self.horizontalLayout_7.addWidget(self.lineEdit5)
self.etiqueta13 = QLabel(self.frame8)
#self.etiqueta13.setObjectName(_fromUtf8("etiqueta13"))
self.horizontalLayout_7.addWidget(self.etiqueta13)
self.verticalLayout_3.addLayout(self.horizontalLayout_7)
self.horizontalLayout_8 = QHBoxLayout()
#self.horizontalLayout_8.setObjectName(_fromUtf8("horizontalLayout_8"))
self.etiqueta14 = QLabel(self.frame8)
#self.etiqueta14.setObjectName(_fromUtf8("etiqueta14"))
self.horizontalLayout_8.addWidget(self.etiqueta14)
self.lineEdit6 = QLineEdit(self.frame8)
self.lineEdit6.setMaximumSize(QSize(90, 16777215))
#self.lineEdit6.setObjectName(_fromUtf8("lineEdit6"))
self.horizontalLayout_8.addWidget(self.lineEdit6)
self.etiqueta15 = QLabel(self.frame8)
#self.etiqueta15.setObjectName(_fromUtf8("etiqueta15"))
self.horizontalLayout_8.addWidget(self.etiqueta15)
self.verticalLayout_3.addLayout(self.horizontalLayout_8)
self.verticalLayout_5.addLayout(self.verticalLayout_3)
spacerItem8 = QSpacerItem(20, 13, QSizePolicy.Minimum,QSizePolicy.Expanding)
self.verticalLayout_5.addItem(spacerItem8)
self.verticalLayout_7 = QVBoxLayout()
#self.verticalLayout_7.setObjectName(_fromUtf8("verticalLayout_7"))
self.horizontalLayout_14 = QHBoxLayout()
#self.horizontalLayout_14.setObjectName(_fromUtf8("horizontalLayout_14"))
spacerItem9 = QSpacerItem(40, 20, QSizePolicy.Expanding,QSizePolicy.Minimum)
self.horizontalLayout_14.addItem(spacerItem9)
self.boton1 = QPushButton(self.frame8)
#self.boton1.setObjectName(_fromUtf8("boton1"))
self.horizontalLayout_14.addWidget(self.boton1)
spacerItem10 = QSpacerItem(40, 20, QSizePolicy.Expanding,QSizePolicy.Minimum)
self.horizontalLayout_14.addItem(spacerItem10)
self.verticalLayout_7.addLayout(self.horizontalLayout_14)
self.horizontalLayout_15 = QHBoxLayout()
#self.horizontalLayout_15.setObjectName(_fromUtf8("horizontalLayout_15"))
spacerItem11 = QSpacerItem(40, 20, QSizePolicy.Expanding,QSizePolicy.Minimum)
self.horizontalLayout_15.addItem(spacerItem11)
self.boton2 = QPushButton(self.frame8)
#self.boton2.setObjectName(_fromUtf8("boton2"))
self.horizontalLayout_15.addWidget(self.boton2)
spacerItem12 = QSpacerItem(40, 20, QSizePolicy.Expanding,QSizePolicy.Minimum)
self.horizontalLayout_15.addItem(spacerItem12)
self.verticalLayout_7.addLayout(self.horizontalLayout_15)
self.verticalLayout_5.addLayout(self.verticalLayout_7)
spacerItem13 = QSpacerItem(20, 18, QSizePolicy.Minimum,QSizePolicy.Expanding)
self.verticalLayout_5.addItem(spacerItem13)
if self.band1==True and self.band2==False :
self.etiqueta2.setText("Carga Conectada")#tenia un problema para guardar
self.etiqueta3.setText("R")#solucione, al copiar textualmente cada linea de estos setText
self.etiqueta4.setText("a")
self.etiqueta5.setText("X")
self.etiqueta6.setText("a")
self.etiqueta7.setText("Parametros de las lineas")#si coloco acentos el programa se cuelga
self.etiqueta8.setText("Zo1")
self.etiqueta9.setText("a")
self.etiqueta10.setText("Zo2")
self.etiqueta11.setText("a")
self.etiqueta12.setText("f")
self.etiqueta13.setText("MHz").o so
self.etiqueta14.setText("Vf")
self.etiqueta15.setText("%C")
self.boton1.setText('Calcular')
self.boton2.setText('Ayuda')
print('Impedancia')
elif self.band1==False and self.band2==True :
self.etiqueta2.setText("Carga Conectada")#tenia un problema para guardar
self.etiqueta3.setText("G")#solucione, al copiar textualmente cada linea de estos setText
self.etiqueta4.setText("a")
self.etiqueta5.setText("B")
self.etiqueta6.setText("a")
self.etiqueta7.setText("Parametros de las lineas")#si coloco acentos el programa se cuelga
self.etiqueta8.setText("Yo1")
self.etiqueta9.setText("a")
self.etiqueta10.setText("Yo2")
self.etiqueta11.setText("a")
self.etiqueta12.setText("f")
self.etiqueta13.setText("MHz")
self.etiqueta14.setText("Vf")
self.etiqueta15.setText("%C")
self.boton1.setText('Calcular')
self.boton2.setText('Ayuda')
print('Admitancia')
return self.frame8#sin esta linea, el show() invocado en el llamarimpedancia sera desconocido
if __name__=="__main__":
app=QApplication(sys.argv)
myapp=stub1()
myapp.show()
app.exec_()
#sys.exit(app.exec_())