AstroLinux | 2021-05-13 22:25:55 UTC | #1
Hello, I get the error during run the code from Listing 13. basic/widgets_1.py (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/main.py", line 24, in <module>
window = MainWindow()
File "/home/oleh/PycharmProjects/pythonProject5/main.py", line 17, in __init__
widget.setAlignment( Qt.Alignment.AlignHCenter | Qt.Alignment.AlignVCenter) # <2>
AttributeError: type object 'Qt' has no attribute 'Alignment'
PedanticHacker | 2021-05-13 22:49:03 UTC | #2
Hello, @AstroLinux, welcome to the forum!
Try changing Qt.Alignment
to Qt.AlignmentFlag
and it should work.
martin | 2021-05-14 16:15:56 UTC | #3
@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.
PyQt6 Crash Course — a new tutorial in your Inbox every day
Beginner-focused crash course explaining the basics with hands-on examples.
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 https://account.mfitzp.com (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 :D
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.