I have to add:
import sys
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow
from PyQt5.QtCore import Qt
and changed:
class MainWindow(QtWidgets.QMainWindow):
to
class MainWindow(QMainWindow):
and add:
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
for this example to work.