I have a function defined like this:
def func(self, boolVal):
and I want to create a connection between QPushButton() and this function like this:
self.button1.clicked.connect(partial(self.func, False))
when I run this, it tells me that func() takes exactly 2 arguments (3 given)
anyone knows why this could happened?
functools.partial works fine.
See following example:
from functools import partial
from PyQt4.QtGui import *
class MyWindow(QWidget):
def __init__(self):
super(QWidget, self).__init__()
self.button = QPushButton('test', parent=self)
self.button.clicked.connect(partial(self.func, False))
self.button.show()
def func(self, boolVar):
print boolVar
app = QApplication([])
win = MyWindow()
win.show()
app.exec_()
If you still get error replace func signature with:
def func(self, boolVar, checked):
print boolVar
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