Image inserted in label using designer does not load from python

Heads up! You've already completed this tutorial.

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 : image|353x268 Anything I need to do in addition? Here image is called in GUI when I write out the Python code: image|473x51

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

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 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).

Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt6
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Leanpub and Amazon Paperback

[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

Image inserted in label using designer does not load from python 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.