问题
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
回答1:
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))
来源:https://stackoverflow.com/questions/65204163/picture-not-showing-on-my-loading-screen-in-qlabel