gpt4 book ai didi

python - 属性错误 : 'StartQT4' object has no attribute 'accept'

转载 作者:太空宇宙 更新时间:2023-11-04 06:55:14 27 4
gpt4 key购买 nike

我正在尝试使用 QT4 和 Python 编写一个快速对话。我已经使用 pyuic4 生成了 Python 类,并尝试制作一个小的 python 脚本来启动它:

import sys
from PyQt4 import QtCore, QtGui
from ConfigGUI import Ui_ConfigGUI

class StartQT4(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_ConfigGUI()
self.ui.setupUi(self)


if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = StartQT4()
myapp.show()
sys.exit(app.exec_())

当我尝试运行它时,它显示 AttributeError: 'StartQT4' object has no attribute 'accept'

我做错了什么?

最佳答案

我成功地重现了你的问题。您在 QtDesigner 中选择了一个基于对话框的窗体,但正试图在 QMainWindow 中构建它。

Form base selection dialog in QtDesigner

UI 代码尝试将其按钮绑定(bind)到默认对话框插槽 acceptreject,这在 QMainWindow 中不可用。

来自 ConfigGUI.py:

QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)

The class contains a method called setupUi(). This takes a single argument which is the widget in which the user interface is created. The type of this argument (typically QDialog, QWidget or QMainWindow) is set in Designer. We refer to this type as the Qt base class.

-- http://pyqt.sourceforge.net/Docs/PyQt4/designer.html

所以,要么选择Designer中的Main Window作为基类,要么将StartQT4的继承改为QtGui。 QDialog.

关于python - 属性错误 : 'StartQT4' object has no attribute 'accept' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29303901/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com