Python 3.x 在哪里可以找到PyQt5方法签名?

Python 3.x 在哪里可以找到PyQt5方法签名?,python-3.x,pyqt5,method-signature,keyword-argument,Python 3.x,Pyqt5,Method Signature,Keyword Argument,我想编写一个带有图形用户界面的小应用程序,为此我安装了PyQt5。在一个教程中,我发现一个QMessageBox.information(..)调用已经完成 我想更改通话,以便: QMessageBox.information(self, "Empty Field", "Please enter a name and address.") 我写关键字参数,这样我就知道哪些参数代表哪些内容,这样,当我在一年内阅读它时,我就立即知道它是关于什么的。所以我试着: QMessageBox.inform

我想编写一个带有图形用户界面的小应用程序,为此我安装了PyQt5。在一个教程中,我发现一个QMessageBox.information(..)调用已经完成

我想更改通话,以便:

QMessageBox.information(self, "Empty Field", "Please enter a name and address.")
我写关键字参数,这样我就知道哪些参数代表哪些内容,这样,当我在一年内阅读它时,我就立即知道它是关于什么的。所以我试着:

QMessageBox.information(parent=self, title="Empty Field", message="Please enter a name and address.")
在执行时,会出现以下错误:

Traceback (most recent call last):
File "SimpleExample.py", line 39, in submitContact
QMessageBox.information(parent=self, title="Empty Field", message="Please enter a name and address.")
TypeError: QMessageBox.information(QWidget, str, str, QMessageBox.StandardButtons buttons=QMessageBox.Ok, QMessageBox.StandardButton defaultButton=QMessageBox.NoButton): 'message' is not a valid keyword argument
所以我的猜测是错误的,但是我如何找出真正的方法签名呢? 我搜索了一会儿,找到了这个函数:

from inspect import getcallargs
getcallargs()
我试着这样使用它:

>>> from inspect import getcallargs
>>> from PyQt5.QtWidgets import *
>>> from PyQt5.QtCore import *
>>> getcallargs(QMessageBox.information(), a=1, b=2)
但这也不起作用:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: QMessageBox.information(QWidget, str, str, QMessageBox.StandardButtons buttons=QMessageBox.Ok, QMessageBox.StandardButton defaultButton=QMessageBox.NoButton): not enough arguments
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:QMessageBox.information(QWidget,str,str,QMessageBox.StandardButtons buttons=QMessageBox.Ok,QMessageBox.StandardButton defaultButton=QMessageBox.NoButton):参数不足
不管我加了多少个参数(函数1,2,3,4,5,6,7,8,…),都是不够的。如果它是关于information()的参数,那么我应该如何找到我想要获得参数的函数的正确数量的参数

所以我想“好吧,让我们看看我是否能在QT5文档中找到方法”,但是当然,我只重定向到C++文档的QT5,并且没有列出QMessageBox的函数“信息”,所以我仍然不知道关键字的名称。


如何计算这些名称?

在PyQt中,关键字参数仅支持可选参数,因此不能将它们用作记录函数签名的常规方法

获取正确方法签名的快速方法是在python交互式会话中使用
help
函数:

>>> from PyQt5 import Qt
>>> help(Qt.QMessageBox.information)
...

Help on built-in function information:

information(...)
    QMessageBox.information(QWidget, str, str, QMessageBox.StandardButtons buttons=QMessageBox.Ok, QMessageBox.StandardButton defaultButton=QMessageBox.NoButton) -> QMessageBox.StandardButton
这表明只有
按钮
默认按钮
可用作关键字参数


<> P>重要的是,你要做这件事,而不是看QT文档,因为不能保证C++参数名匹配PyQT使用的(更详细的信息,请参阅PyQT文档)。非常感谢。我真的有一个错误的印象,那就是我总是可以使用关键字参数,而这只是让事情更可读的一种方式。