Alexis_Labuschagne | 2020-09-02 13:02:57 UTC | #1
In PyQT5 designer I insert an image into a label but the image does not show when I run it in python. It shows in designer : Anything I need to do in addition? Here image is called in GUI when I write out the Python code:
martin | 2020-09-04 19:18:52 UTC | #2
Looking at the code in the second block, the image is referenced using a
QResource path -- starting with the colon
:. This is a virtual path referencing a file in the Qt Resource system, used by Qt to bundle assets. For those paths to work in Python you need to first compile the resource file to Python code and then import it into your application.
You can compile it using the
pyrcc5 command (change the name of your file as needed).
pyrcc5 resources.qrc -o resources.py
This compile step goes through all the files referenced in the
.qrc file, copying their data (and resource name) into a Python data structure. When you import the resulting
resources.py file, these files become available to Qt under theit resource paths (beginning with
There is covered with some more examples in the book's QResource chapter (under Designer).