Ive created a program using pyqt4 as GUI Ive used resource file or .qrc to load background image.
My problem is when i compiled it using py2exe, the background image is not loaded.
here is the sample code.
GUI MODULE:
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(563, 319)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setStyleSheet(_fromUtf8("background-image: url(:/test/mr_bean_kid.jpg);"))
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 563, 18))
self.menubar.setObjectName(_fromUtf8("menubar"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
import ss_rc
MAIN MODULE:
from sample import Ui_MainWindow
from PyQt4 import QtCore, QtGui
class test(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
myapp = test()
myapp.show()
sys.exit(app.exec_())
i will not include the qrc because its to long.
thx.
The solution to your problem can be found at the bottom of this page.
http://www.py2exe.org/index.cgi/Py2exeAndPyQt
When trying this solution, make sure you are not bundling all files into a single executable, that won’t work…