AttributeError: type object 'Qt' has no attribute 'Alignment'

I get the error during run the code from Listing 13. basic/ (page 38, “Create GUI Applications with Python & Qt6” The hands-on guide to making apps with Python Version 1.0, 2021-04-09).

Traceback (most recent call last):
  File "/home/oleh/PycharmProjects/pythonProject5/", line 24, in <module>
    window = MainWindow()
  File "/home/oleh/PycharmProjects/pythonProject5/", line 17, in __init__
    widget.setAlignment( Qt.Alignment.AlignHCenter | Qt.Alignment.AlignVCenter)  # <2>
AttributeError: type object 'Qt' has no attribute 'Alignment'

Hello, @AstroLinux, welcome to the forum!

Try changing Qt.Alignment to Qt.AlignmentFlag and it should work.


@AstroLinux this is due to a change in PyQt 6.1 (released 11th May) – the enum names were updated to bring it in line with PySide6.

It’s a good change, as it keeps PyQt/PySide more compatible, but it does mean I need to re-do all the code examples in the book! I’ll be releasing an update shortly to fix this.

edit: @AstroLinux @PedanticHacker the updated version of the PyQt6 (for 6.1) has been uploaded now. You can download it from (once logged in).

There weren’t that many changes in the end, still I may have missed some – let me know if you spot anything amiss. I wanted to get this out quickly as I’ve already have 5 emails about it this morning :smiley: