PyQt5 Attribute Error: 'GUI' object has no attribute 'setLayout'
<p>There seems to be an attribute error when I run my code. Specifically, the error I encounter is:</p>

<pre><code>AttributeError: 'GUI' object has no attribute 'setLayout'
</code></pre>

<p>The code I'm currently using:</p>

<pre><code>class GUI(object):
    def __init__(self):
        super(GUI,self).__init__()
        self.initUI()

    def initUI(self):
        review = QtWidgets.QLabel('Review')
        reviewEdit = QtWidgets.QTextEdit()
        grid = QtWidgets.QGridLayout()

        grid.addWidget(review, 3, 0)
        grid.addWidget(reviewEdit, 3, 1, 5, 1)
        self.setLayout(grid)
        self.setGeometry(300,300,350,300)
        self.setWindowTitle('Sentiment Analysis')
        self.show()
</code></pre>

<p>You get an attribute error because neither your class nor <code>object</code> defines the methods you try to access through <code>self</code>. You need to inherit these from a <code>Qt</code> class that defines them. For example, inheriting from <code>QWidget</code>.</p>

<pre><code>from PyQt5 import QtWidgets

class GUI(QtWidgets.QWidget):
     ...
</code></pre>

<p>will makes these available for your class. Substitute the appropriate <code>PyQt</code> base class for your use case to get the functionality.</p>

python python-3.x pyqt5