Create dynamic button in PyQt
pyqt, python, qt
Solution
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
Problem
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 !