I try to add a function in a PyQt class, but it always returns me an error.
# Error: TypeError: connect() slot argument should be a callable or a signal, not 'NoneType' #
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
May be someone here can help me to solve that :') Thx !
You need a function:
button.clicked.connect(lambda: self.commander(command))
Note the lambda will avoid the evaluation of the function call, so it'll call self.commander(command)
only when clicked
appears that in
button.clicked.connect(self.commander(command))
self.commander(command)
is returning None
instead of a signal or a callable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With