求助:使用pyqt5时运行报错'mywindow' object has no attribute 'accept'
UI文件:from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(254, 134)
self.widget = QtWidgets.QWidget(Dialog)
self.widget.setGeometry(QtCore.QRect(30, 40, 195, 65))
self.widget.setObjectName("widget")
self.gridLayout = QtWidgets.QGridLayout(self.widget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.NG = QtWidgets.QPushButton(self.widget)
self.NG.setMouseTracking(False)
self.NG.setObjectName("NG")
self.gridLayout.addWidget(self.NG, 0, 0, 1, 1)
self.buttonBox = QtWidgets.QDialogButtonBox(self.widget)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.gridLayout.addWidget(self.buttonBox, 1, 0, 1, 1)
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept)
self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.NG.setText(_translate("Dialog", "PushButton"))
后端:
from PyQt5 import QtWidgets
from test import Ui_Dialog
class mywindow(QtWidgets.QMainWindow, Ui_Dialog):
def __init__ (self):
super(mywindow, self).__init__()
self.setupUi(self)
if __name__=="__main__":
import sys
app=QtWidgets.QApplication(sys.argv)
ui = mywindow()
ui.show()
sys.exit(app.exec_())
报错:[local]1[/local]