TypeError: __init__() takes 1 positional argument but 2 were given

Rich Shepard rshepard at appl-ecosys.com
Thu Apr 29 16:33:25 BST 2021


I'm trying to add a tab's content to a QTabWidget but get this error:
$ python mwe.py 
Traceback (most recent call last):
   File "mwe.py", line 31, in <module>
     mw = MainWindow()
   File "mwe.py", line 20, in __init__
     self.sw = SitesWindow(self)
TypeError: __init__() takes 1 positional argument but 2 were given

It's been a long time since I did any serious python coding and despite my
researching this error on the Web I still fail to see the solution. I know
it's simple but I don't see the two arguments to the assignment. An minimal
example is attached.

Please point out my error.

TIA,

Rich

-------------- next part --------------
#!/usr/bin/env python3

import sys

from PyQt5 import QtWidgets as qtw
from PyQt5 import QtGui as qtg
from PyQt5 import QtCore as qtc

from views.sites import SitesWindow

class MainWindow(qtw.QMainWindow):
    def __init__(self):
        """MainWindow constructor"""
        super().__init__()

        self.setWindowTitle('NWE')
        self.statusBar()

        # tab contents
        self.sw = SitesWindow(self) # line 30 in error msg
        
        tabs = qtw.QTabWidget()
        tabs.setMovable(False)
        # add tab pages here
        tabs.addTab(self.sw)
      
        self.show()

if __name__ == '__main__':
    app = qtw.QApplication(sys.argv)
    mw = MainWindow()
    sys.exit(app.exec())       





More information about the PyQt mailing list