简体   繁体   中英

Picture not showing on my loading screen in QLabel

I'm currently using QT designer to show a picture on my loading screen.

It should look like this: 在此处输入图像描述

However, it looks like this: 在此处输入图像描述

This is because for some reason its not showing my picture, when it registers in my IDE that the filepath is correct as seen here: 在此处输入图像描述

The only time the picture actually shows in my loading GUI is when I use the FULL file path which is: C:\Users\myalt\OneDrive\Desktop\GUINEW\assets\PostmonkeyLogo.png

But of course, this is not viable when this software will be used on many different computer with different file paths.

self.label.setPixmap(QPixmap(u"assets/PostmonkeyLogo.png")) ## image file path to show

The problem is that the file path is relative to where the console was opened and the python.exe command is executed. It is better to build the full path using the information as the path of the.py:

import os.path

# ...

CURRENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
filename = os.path.join(CURRENT_DIRECTORY, "assets/PostmonkeyLogo.png")
self.label.setPixmap(QPixmap(filename))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM