I am completely new to PyQt5, and I wanted to insert an image in a "Dialog with Buttons" window I created with the designer (I don't know if that influeces something, so I mention it)
I followed the instructions this stackoverflow answer gave me, and I did as follows:
- I created a new resource named "Test"
- I added a prefix named "PrefixTest"
- I added an image, found on a folder named "Testings" on my desktop
All the files I made (the Test.qrc, the image and the .ui file) are all on that folder
Then I converted the resulting .ui
to .py
using pyui5.py
, and when I run the resulting file, the following error pops up on console
File "C:\Users\MyUserName\Desktop\Testings\FirstUI.py", line 44, in <module>
import Test_rc
ImportError: No module named 'Test_rc'
When I manually remove that line of code, the rest of UI appears and only the image is missing, so I can confidently say the error involves the image
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(391, 178)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(20, 120, 341, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.textBrowser = QtWidgets.QTextBrowser(Dialog)
self.textBrowser.setGeometry(QtCore.QRect(10, 20, 371, 61))
self.textBrowser.setObjectName("textBrowser")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(20, 100, 61, 71))
self.label.setObjectName("label")
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept)
self.buttonBox.rejected.connect(Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.textBrowser.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Hello world!</p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">This is a test of the current technology we posess in our hands. Whatever we obtain here shall not be shown to any other human being without proper authorization</p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">One day this fleeting moment in spacetime will be remembered, or probably not, I am no omnipotent being</p></body></html>"))
self.label.setText(_translate("Dialog", "<html><head/><body><p><img src=\":/PrefixTest/Computer.png\"/></p></body></html>"))
import Test_rc
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())