Nigel_Trewartha | 2020-05-07 15:08:46 UTC | #1
I am using WIngIDE Pro version 7.2.2.2 on a WIn 10 64bit Pro. and am using the code under the "Signals. Slots and Events.
https://www.pythonguis.com/courses/start/signals-slots-events/#jc8dc3b580-deef-49f8-bf79-a2e67e6fa50a
I get this error;
Traceback (most recent call last):
File "D:\Eigene Dateien\PYQT5_Sources\test4-signals and slots1.py", 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??
Purchasing Power Parity
Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]martin | 2020-05-07 15:10:11 UTC | #2
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):
or
from PyQt5.QtWidgets import QApplication, QMainWindow
Will update this tutorial to include the full code to start with as this is very confusing.
Nigel_Trewartha | 2020-05-07 15:10:31 UTC | #3
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 MyApp_window.py
and save it under a new name for this section". I assume you mean one of the exercises in the last section..
Nigel_Trewartha | 2020-05-07 15:11:15 UTC | #4
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.
martin | 2020-05-18 11:53:34 UTC | #6
[quote="Nigel_Trewartha, post:3, topic:32"] Perhaps an idea to include this in your code. [/quote]
I've added the base code to the top of the tutorial, should make it clearer -- thanks for the feedback!
PyQt6 Crash Course — a new tutorial in your Inbox every day
Beginner-focused crash course explaining the basics with hands-on examples.