I recently encountered this error after attempting to run my python script. In short, I simply don't understand how I've fed three arguments. I've included what I considered to be the most relevant snippets of code. Help is very appreciated. Thank you.
Traceback (most recent call last): File "DESeq_rpkm_gui.py", line 946, in disp = Ui_MainWindow() File "DESeq_rpkm_gui.py", line 21, in init self.setupUi(self,QMainWindow) TypeError: setupUi() takes exactly 2 arguments (3 given)
class Ui_MainWindow(QMainWindow):
def __init__(self,parent=None):
QMainWindow.__init__(self,parent)
self.setupUi(self,QMainWindow)
def setupUi(self,MainWindow):
and
if __name__=='__main__':
app = QApplication(sys.argv)
disp = Ui_MainWindow()
disp.show()
sys.exit(disp.exec_())
When you call a method as
object.method(argument1, ...)
thenobject
is implicitly passed to the method as the first argument.So with your current code, the line
self.setupUi(self,QMainWindow)
is actually passing three arguments to the methodsetupUi
. They areself
,self
(again) andQMainWindow
.You might want to read this: What is the purpose of self?
Now, you may have been confused by this because PyQt is a bit unorthodox in how you call/use the
setupUi
method. The documentation is here for your reference, but in short, they expect you to callself.setupUi(self)
.This is so that you can use the
setupUi
method to create your UI in any widget you pass in (or even more than one!). This is explained in the first example of the documentation:You are using what I consider the more conventional approach, and calling
setupUi
from within your__init__
method. This is covered in the second example in their documentation, and should be called as I outlined above.