标题:求助:使用pyqt5时运行报错'mywindow' object has no attribute 'accept'
只看楼主
浅湾
Rank: 1
等 级:新手上路
帖 子:8
专家分:7
注 册:2020-5-27
结帖率:100%
已结贴  问题点数:20 回复次数:1 
求助:使用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]
搜索更多相关主题的帖子: 报错 import accept object 
2020-05-27 09:19
古123
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:219
专家分:1098
注 册:2017-2-5
得分:20 
blog.
2020-05-28 08:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-501815-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.565727 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved