[Python] user32.SetWindowCompositionAttribute with PyQt5 causes ctypes.ArgumentError

Discussão em 'Python' iniciado por Stack, Novembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    Recently I installed a python package called BlurWindow via

    pip install BlurWindow


    This python package helps to achieve a transparent blur background to the application window. Although it says that this module works with tkinter, qt and many other packages, but in my case it only works with tkinter and PySide2 but not with PyQt5.

    My code can be seen below:

    import sys

    from PySide2.QtWidgets import *
    from PySide2.QtCore import *

    # from PyQt5.QtWidgets import *
    # from PyQt5.QtCore import *

    from BlurWindow.blurWindow import GlobalBlur


    class MainWindow(QWidget):
    def __init__(self):
    super(MainWindow, self).__init__()
    self.setAttribute(Qt.WA_TranslucentBackground)
    # self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint | Qt.WindowMinMaxButtonsHint) # set window flags
    self.resize(500, 400)

    l = QLabel('How do you like the blurry window?', self)

    GlobalBlur(self.winId(), Dark=False, Acrylic=False, QWidget=self)

    self.setStyleSheet("color: white; background-color: rgba(0, 0, 0, 0)")


    if __name__ == '__main__':
    app = QApplication(sys.argv)
    mw = MainWindow()
    mw.show()
    sys.exit(app.exec_())


    This code works fine. But when I comment these two lines (line 3 and 4):

    from PySide2.QtWidgets import *
    from PySide2.QtCore import *


    and uncomment these two lines (line 6 and 7):

    from PyQt5.QtWidgets import *
    from PyQt5.QtCore import *


    this error occurs:

    Traceback (most recent call last):
    File "E:\PythonProjects\Zambo\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
    File "E:\PythonProjects\Zambo\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
    File "E:\PythonProjects\Zambo\lib\site-packages\BlurWindow\blurWindow.py", line 191, in <module>
    mw = MainWindow()
    File "E:\PythonProjects\Zambo\lib\site-packages\BlurWindow\blurWindow.py", line 185, in __init__
    GlobalBlur(hWnd,Dark=True,QWidget=self)
    File "E:\PythonProjects\Zambo\lib\site-packages\BlurWindow\blurWindow.py", line 160, in GlobalBlur
    blur(HWND,hexColor,Acrylic,Dark)
    File "E:\PythonProjects\Zambo\lib\site-packages\BlurWindow\blurWindow.py", line 136, in blur
    user32.SetWindowCompositionAttribute(HWND, data)
    ctypes.ArgumentError: argument 1: <class 'TypeError'>: Don't know how to convert parameter 1


    I don't know why this code works with PySide2 but doesn't work with PyQt5!

    This is the blurWindow.py module that I'm using in the shown code.

    I am on windows 10 and using Python 3.9.5 on an anaconda virtual environment. But I have tested this code on Python 3.6 and 3.8 but the PyQt5 library doesn't work anywhere, instead shows that same error.

    I have almost finished my project in which I will implement this blur effect. And since I've used PyQt5 library in my project, replacing PyQt5 library with PySide2 will be a big trouble for me. Any help would be highly appreciated!

    Continue reading...

Compartilhe esta Página