AttributeError: 'MainWindow' object has no attribute 'onWindowTitleChange'

Heads up! You've already completed this tutorial.

Jomali_3945 | 2020-05-07 14:43:37 UTC | #1

While running your example, I get the error: AttributeError: 'MainWindow' object has no attribute 'onWindowTitleChange'

https://www.pythonguis.com/courses/start/signals-slots-events/


Wu_Yi | 2020-05-07 14:45:26 UTC | #2

I had the same problem, it seems that this signal is no longer available in the Qt QMainWindow class.


martin | 2020-05-10 09:41:25 UTC | #3

The onWindowTitleChange is a custom-defined slot (see the bottom of the example file) which you need to add yourself. The signal windowTitleChange is connected to this.

1:1 Coaching & Tutoring for your Python GUIs project
Martin Fitzpatrick Python GUIs Coaching & Training
60 mins ($195) Book Now

1:1 Python GUIs Coaching & Training

Comprehensive code reviewBugfixes & improvements • Maintainability advice and architecture improvements • Design and usability assessment • Suggestions and tips to expand your knowledgePackaging and distribution help for Windows, Mac & Linux • Find out more.

python
# SLOT: This accepts a string, e.g. the window title, and prints it
def onWindowTitleChange(self, s):
    print(s)

Wu_Yi | 2020-05-10 09:41:24 UTC | #4

Thanks, that makes sense.

Create GUI Applications with Python & Qt5 by Martin Fitzpatrick — (PyQt5 Edition) The hands-on guide to making apps with Python — Over 15,000 copies sold!

More info Get the book


tashasummers5448 | 2020-07-21 20:49:05 UTC | #5

I got the same error but my mistake was that I had copy/pasted the slots into the same indent level as the class MainWindow instead of the indent level of the def __init__. It worked once I moved them over.

Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.

More info Get the book


Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak
Martin Fitzpatrick

AttributeError: 'MainWindow' object has no attribute 'onWindowTitleChange' was written by Martin Fitzpatrick.

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular Python books on the subject.