Signals, Slots and Events: NameError: name 'QMainWindow' is not defined

I am using WIngIDE Pro version on a WIn 10 64bit Pro.
and am using the code under the "Signals. Slots and Events.

I get this error;

Traceback (most recent call last):
File "D:\Eigene Dateien\PYQT5_Sources\test4-signals and", line 5, in <module>
class MainWindow(QMainWindow):
NameError: name 'QMainWindow' is not defined

Process terminated with an exit code of 1

I even changed to code to include this:

import sys
from PyQt5.QtWidgets import QApplication
import PyQt5

So I appear to be doing something very wrong. Can I get help here please??

Hi Nigel, welcome to the site!

This is because you don’t have an import for QMainWindow. You can either import QMainWindow itself or you can import QtWidgets and access QMainWindow through there.

class MainWindow(QtWidgets.QMainWindow):


from PyQt5.QtWidgets import QApplication, QMainWindow

Will update this tutorial to include the full code to start with as this is very confusing.

1 Like

Thany you for your reply. I copied your code. That does have a Mainwindow. Perhaps an idea to include this in your code.

I also cannot find “Load up a fresh copy of and save it under a new name for this section”. I assume you mean one of the exercises in the last section…

I added the import from PyQt5.QtWidgets import QApplication, QMainWindow

But when I start the programme it seems to do nothing. Tried it under WingIDE pro and cmd -> python “filename”

Since I just copied and pasted your programme snippet and added from PyQt5.QtWidgets import QApplication, QMainWindow . I do not see what I am doing wrong.

I’ve added the base code to the top of the tutorial, should make it clearer – thanks for the feedback!