我尝试在PyQt类中添加一个函数,但它总是返回一个错误.
# Error: TypeError: connect() slot argument should be a callable or a signal, not 'NoneType' #
Run Code Online (Sandbox Code Playgroud)
def commander (self, arg):
exec arg
def aButton (self, layout, **kwargs):
name = kwargs.pop("name","Button")
command = kwargs.pop("command", "" )
button = QtGui.QPushButton(name)
button.clicked.connect(self.commander(command))
layout.addWidget(button)
return button
Run Code Online (Sandbox Code Playgroud)
可能是这里有人可以帮我解决:')Thx!
JBe*_*rdo 27
你需要一个功能:
button.clicked.connect(lambda: self.commander(command))
Run Code Online (Sandbox Code Playgroud)
请注意,lambda将避免对函数调用进行评估,因此self.commander(command)只有在单击时才会调用
| 归档时间: |
|
| 查看次数: |
7959 次 |
| 最近记录: |