作为此代码的QTabWidget缺少的方法写的?

时间:2016-10-24 05:56:08

标签: python python-3.x pyqt pyqtgraph qt5.6

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(窗口)

我如何修复// AttributeError:'QDialog'对象没有属性'addTab'

当他试图运行代码时,我在两行都出错了,所以我想不出任何新的东西,也不明白我已经阅读了很多解释

1 个答案:

答案 0 :(得分:1)

你的setupUi方法需要一个QTabWidget,但是你的代码正在传递一个QDialog。虽然我目前没有设置PyQt5环境进行测试,但您应该只需将window = QDialog替换为window = QTabWidget()以下的#Qwidget Call