这段代码缺少的QTabWidget方法是怎么写的?
as the missing method of QTabWidget of this code is written?
import sys,random
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow,QDialog
class Ui_TabWidget(object):
def setupUi(self, TabWidget):
TabWidget.setObjectName("TabWidget")
TabWidget.resize(264, 113)
self.PILA = QtWidgets.QWidget()
self.PILA.setObjectName("PILA")
self.LineMOSTRAR = QtWidgets.QLineEdit(self.PILA)
self.LineMOSTRAR.setGeometry(QtCore.QRect(10, 50, 231, 21))
self.LineMOSTRAR.setObjectName("LineMOSTRAR")
self.BtnINSERTA = QtWidgets.QPushButton(self.PILA)
self.BtnINSERTA.setGeometry(QtCore.QRect(10, 10, 75, 23))
self.BtnINSERTA.setObjectName("BtnINSERTA")
self.BtnSALIR = QtWidgets.QPushButton(self.PILA)
self.BtnSALIR.setGeometry(QtCore.QRect(170, 10, 75, 23))
self.BtnSALIR.setObjectName("BtnSALIR")
self.BtnELIMINA = QtWidgets.QPushButton(self.PILA)
self.BtnELIMINA.setGeometry(QtCore.QRect(90, 10, 75, 23))
self.BtnELIMINA.setObjectName("BtnELIMINA")
根据 python 我的错误在 TabWidget.addTab
TabWidget.addTab(self.PILA, "") #This is mi error according pyqt5
self.COLA = QtWidgets.QWidget()
self.COLA.setObjectName("COLA")
self.BtnINSERTA_2 = QtWidgets.QPushButton(self.COLA)
self.BtnINSERTA_2.setGeometry(QtCore.QRect(10, 10, 75, 23))
self.BtnINSERTA_2.setObjectName("BtnINSERTA_2")
self.BtnELIMINA_2 = QtWidgets.QPushButton(self.COLA)
self.BtnELIMINA_2.setGeometry(QtCore.QRect(90, 10, 75, 23))
self.BtnELIMINA_2.setObjectName("BtnELIMINA_2")
self.BtnSALIR_2 = QtWidgets.QPushButton(self.COLA)
self.BtnSALIR_2.setGeometry(QtCore.QRect(170, 10, 75, 23))
self.BtnSALIR_2.setObjectName("BtnSALIR_2")
self.LineMOSTRAR_2 = QtWidgets.QLineEdit(self.COLA)
self.LineMOSTRAR_2.setGeometry(QtCore.QRect(10, 50, 231, 21))
self.LineMOSTRAR_2.setObjectName("LineMOSTRAR_2")
TabWidget.addTab(self.COLA, "")
self.COLA_C = QtWidgets.QWidget()
self.COLA_C.setObjectName("COLA_C")
self.BtnINSERTA_3 = QtWidgets.QPushButton(self.COLA_C)
self.BtnINSERTA_3.setGeometry(QtCore.QRect(10, 10, 75, 23))
self.BtnINSERTA_3.setObjectName("BtnINSERTA_3")
self.BtnELIMINA_3 = QtWidgets.QPushButton(self.COLA_C)
self.BtnELIMINA_3.setGeometry(QtCore.QRect(90, 10, 75, 23))
self.BtnELIMINA_3.setObjectName("BtnELIMINA_3")
self.BtnSALIR_3 = QtWidgets.QPushButton(self.COLA_C)
self.BtnSALIR_3.setGeometry(QtCore.QRect(170, 10, 75, 23))
self.BtnSALIR_3.setObjectName("BtnSALIR_3")
self.LineMOSTRAR_3 = QtWidgets.QLineEdit(self.COLA_C)
self.LineMOSTRAR_3.setGeometry(QtCore.QRect(10, 50, 231, 21))
self.LineMOSTRAR_3.setObjectName("LineMOSTRAR_3")
TabWidget.addTab(self.COLA_C, "")
#WIDGET Btn
#Btn for 1st tab of mi app
self.BtnINSERTA.clicked.connect(self.INSERTA)
self.BtnELIMINA.clicked.connect(self.ELIMINA)
self.BtnSALIR.clicked.connect(self.SALIR)
#Btn for 2nd tab of mi app
self.BtnINSERTA.clicked.connect(self.INSERTA_2)
self.BtnELIMINA.clicked.connect(self.ELIMINA_2)
self.BtnSALIR.clicked.connect(self.SALIR_2)
#Btn for 3rd tab of mi app
self.BtnINSERTA.clicked.connect(self.INSERTA_3)
self.BtnELIMINA.clicked.connect(self.ELIMINA_3)
self.BtnSALIR.clicked.connect(self.SALIR_3)
self.retranslateUi(TabWidget)
TabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(TabWidget)
#Method for my btns
def INSERTA(self):
self.LineMOSTRAR.setText('PILA LLENA - DESBORDAMIENTO')
def ELIMINA(self):
self.LineMOSTRAR.setText('PILA VACIA-SUBDESBORDAMIENTO')
def SALIR(self):
exit()
def SALIR_2(self):#RESET Btn
def INSERTA_2(self):
def ELIMINA_2(self):
def INSERTA_3(self):
def ELIMINA_3(self):
def SALIR_3 (self):
exit()
#end of the method
def retranslateUi(self, TabWidget):
_translate = QtCore.QCoreApplication.translate
TabWidget.setWindowTitle(_translate("TabWidget", "TabWidget"))
self.BtnINSERTA.setText(_translate("TabWidget", "Insertar"))
self.BtnSALIR.setText(_translate("TabWidget", "SALIR"))
self.BtnELIMINA.setText(_translate("TabWidget", "Eliminar"))
TabWidget.setTabText(TabWidget.indexOf(self.PILA), _translate("TabWidget", "Tab 1"))
self.BtnINSERTA_2.setText(_translate("TabWidget", "Insertar"))
self.BtnELIMINA_2.setText(_translate("TabWidget", "Eliminar"))
self.BtnSALIR_2.setText(_translate("TabWidget", "RESET"))
TabWidget.setTabText(TabWidget.indexOf(self.COLA), _translate("TabWidget", "Tab 2"))
self.BtnINSERTA_3.setText(_translate("TabWidget", "Insertar"))
self.BtnELIMINA_3.setText(_translate("TabWidget", "Eliminar"))
self.BtnSALIR_3.setText(_translate("TabWidget", "SALIR"))
TabWidget.setTabText(TabWidget.indexOf(self.COLA_C), _translate("TabWidget", "Page"))
#Qwidget Call
app = QApplication(sys.argv)
window = QDialog()
ui = Ui_TabWidget()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())
这是我的错误ui.setupUi(window)
我该如何解决 //AttributeError: 'QDialog' 对象没有属性 'addTab'
当他尝试 运行 时,代码在两行都给我错误,所以我想不出任何新的东西,也不明白我已经阅读了很多解释
您的 setupUi 方法需要一个 QTabWidget,但您的代码向它传递了一个 QDialog。虽然我目前没有设置用于测试的 PyQt5 环境,但您应该能够简单地将 window = QDialog
替换为 #Qwidget Call
.
下面的 window = QTabWidget()
import sys,random
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow,QDialog
class Ui_TabWidget(object):
def setupUi(self, TabWidget):
TabWidget.setObjectName("TabWidget")
TabWidget.resize(264, 113)
self.PILA = QtWidgets.QWidget()
self.PILA.setObjectName("PILA")
self.LineMOSTRAR = QtWidgets.QLineEdit(self.PILA)
self.LineMOSTRAR.setGeometry(QtCore.QRect(10, 50, 231, 21))
self.LineMOSTRAR.setObjectName("LineMOSTRAR")
self.BtnINSERTA = QtWidgets.QPushButton(self.PILA)
self.BtnINSERTA.setGeometry(QtCore.QRect(10, 10, 75, 23))
self.BtnINSERTA.setObjectName("BtnINSERTA")
self.BtnSALIR = QtWidgets.QPushButton(self.PILA)
self.BtnSALIR.setGeometry(QtCore.QRect(170, 10, 75, 23))
self.BtnSALIR.setObjectName("BtnSALIR")
self.BtnELIMINA = QtWidgets.QPushButton(self.PILA)
self.BtnELIMINA.setGeometry(QtCore.QRect(90, 10, 75, 23))
self.BtnELIMINA.setObjectName("BtnELIMINA")
根据 python 我的错误在 TabWidget.addTab
TabWidget.addTab(self.PILA, "") #This is mi error according pyqt5
self.COLA = QtWidgets.QWidget()
self.COLA.setObjectName("COLA")
self.BtnINSERTA_2 = QtWidgets.QPushButton(self.COLA)
self.BtnINSERTA_2.setGeometry(QtCore.QRect(10, 10, 75, 23))
self.BtnINSERTA_2.setObjectName("BtnINSERTA_2")
self.BtnELIMINA_2 = QtWidgets.QPushButton(self.COLA)
self.BtnELIMINA_2.setGeometry(QtCore.QRect(90, 10, 75, 23))
self.BtnELIMINA_2.setObjectName("BtnELIMINA_2")
self.BtnSALIR_2 = QtWidgets.QPushButton(self.COLA)
self.BtnSALIR_2.setGeometry(QtCore.QRect(170, 10, 75, 23))
self.BtnSALIR_2.setObjectName("BtnSALIR_2")
self.LineMOSTRAR_2 = QtWidgets.QLineEdit(self.COLA)
self.LineMOSTRAR_2.setGeometry(QtCore.QRect(10, 50, 231, 21))
self.LineMOSTRAR_2.setObjectName("LineMOSTRAR_2")
TabWidget.addTab(self.COLA, "")
self.COLA_C = QtWidgets.QWidget()
self.COLA_C.setObjectName("COLA_C")
self.BtnINSERTA_3 = QtWidgets.QPushButton(self.COLA_C)
self.BtnINSERTA_3.setGeometry(QtCore.QRect(10, 10, 75, 23))
self.BtnINSERTA_3.setObjectName("BtnINSERTA_3")
self.BtnELIMINA_3 = QtWidgets.QPushButton(self.COLA_C)
self.BtnELIMINA_3.setGeometry(QtCore.QRect(90, 10, 75, 23))
self.BtnELIMINA_3.setObjectName("BtnELIMINA_3")
self.BtnSALIR_3 = QtWidgets.QPushButton(self.COLA_C)
self.BtnSALIR_3.setGeometry(QtCore.QRect(170, 10, 75, 23))
self.BtnSALIR_3.setObjectName("BtnSALIR_3")
self.LineMOSTRAR_3 = QtWidgets.QLineEdit(self.COLA_C)
self.LineMOSTRAR_3.setGeometry(QtCore.QRect(10, 50, 231, 21))
self.LineMOSTRAR_3.setObjectName("LineMOSTRAR_3")
TabWidget.addTab(self.COLA_C, "")
#WIDGET Btn
#Btn for 1st tab of mi app
self.BtnINSERTA.clicked.connect(self.INSERTA)
self.BtnELIMINA.clicked.connect(self.ELIMINA)
self.BtnSALIR.clicked.connect(self.SALIR)
#Btn for 2nd tab of mi app
self.BtnINSERTA.clicked.connect(self.INSERTA_2)
self.BtnELIMINA.clicked.connect(self.ELIMINA_2)
self.BtnSALIR.clicked.connect(self.SALIR_2)
#Btn for 3rd tab of mi app
self.BtnINSERTA.clicked.connect(self.INSERTA_3)
self.BtnELIMINA.clicked.connect(self.ELIMINA_3)
self.BtnSALIR.clicked.connect(self.SALIR_3)
self.retranslateUi(TabWidget)
TabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(TabWidget)
#Method for my btns
def INSERTA(self):
self.LineMOSTRAR.setText('PILA LLENA - DESBORDAMIENTO')
def ELIMINA(self):
self.LineMOSTRAR.setText('PILA VACIA-SUBDESBORDAMIENTO')
def SALIR(self):
exit()
def SALIR_2(self):#RESET Btn
def INSERTA_2(self):
def ELIMINA_2(self):
def INSERTA_3(self):
def ELIMINA_3(self):
def SALIR_3 (self):
exit()
#end of the method
def retranslateUi(self, TabWidget):
_translate = QtCore.QCoreApplication.translate
TabWidget.setWindowTitle(_translate("TabWidget", "TabWidget"))
self.BtnINSERTA.setText(_translate("TabWidget", "Insertar"))
self.BtnSALIR.setText(_translate("TabWidget", "SALIR"))
self.BtnELIMINA.setText(_translate("TabWidget", "Eliminar"))
TabWidget.setTabText(TabWidget.indexOf(self.PILA), _translate("TabWidget", "Tab 1"))
self.BtnINSERTA_2.setText(_translate("TabWidget", "Insertar"))
self.BtnELIMINA_2.setText(_translate("TabWidget", "Eliminar"))
self.BtnSALIR_2.setText(_translate("TabWidget", "RESET"))
TabWidget.setTabText(TabWidget.indexOf(self.COLA), _translate("TabWidget", "Tab 2"))
self.BtnINSERTA_3.setText(_translate("TabWidget", "Insertar"))
self.BtnELIMINA_3.setText(_translate("TabWidget", "Eliminar"))
self.BtnSALIR_3.setText(_translate("TabWidget", "SALIR"))
TabWidget.setTabText(TabWidget.indexOf(self.COLA_C), _translate("TabWidget", "Page"))
#Qwidget Call
app = QApplication(sys.argv)
window = QDialog()
ui = Ui_TabWidget()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())
这是我的错误ui.setupUi(window)
我该如何解决 //AttributeError: 'QDialog' 对象没有属性 'addTab'
当他尝试 运行 时,代码在两行都给我错误,所以我想不出任何新的东西,也不明白我已经阅读了很多解释
您的 setupUi 方法需要一个 QTabWidget,但您的代码向它传递了一个 QDialog。虽然我目前没有设置用于测试的 PyQt5 环境,但您应该能够简单地将 window = QDialog
替换为 #Qwidget Call
.
window = QTabWidget()