<html>
<head>
<style type="text/css">
body,p,td,div,span{
font-size:14px;font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; color: #212121;
};
body p{
margin:0px;
}
</style>
</head>
<body><div>Hi there,</div><div><br></div><div>I tried to create an exe file on Windows 10 with pyinstaller 0.9.2.2. python 3.7, pyQt 5.12 And ended up in a problem with the load.uic() / import from uifile...</div><div>Finally I got it working so far. But there are some problems upcoming.</div><div>1. To use the load.uic() command the ui file must be placed in the directory of the exe file. I want to have a single file, so I used</div><div>2. "pyuic5 testmainwindow.ui -o testmainwindow_ui.py" and "from testmainwindow_ui import Ui_MainWindow" <br></div><div><br></div><div>Both did run, but if I use the import and set e.g. "self.ui.setWindowTitle('Do not read my title')" the app crashes with "AttributeError: 'Ui_MainWindow' object has no attribute 'setWindowTitle'" I don't understand the reason and in addition I have no idea how to solve this. Further ith hangs on <br></div><div> widgetList = self.ui.findChildren (QPushButton)<br>AttributeError: 'Ui_MainWindow' object has no attribute 'findChildren'<br></div><div>The idea behind was that I compile the ui before I run pyinstaller to avoid problems at runtime.<br></div><br><div><br></div><div> To test the behavior just set useUIfile to True in the following example:</div><div>My question: Where is the fault and a how to solve?</div><div><br></div><div>import sys<br>from PyQt5 import uic<br>from PyQt5.QtWidgets import QMainWindow, QApplication<br><br>class window(QMainWindow):<br> def __init__(self):<br> super().__init__()<br> self.init_UI()<br><br> def init_UI(self):<br> useUIfile = True # Change to false to load by raw file<br><br> if useUIfile:<br> # importing file created with pyuic5 testmainwindow.ui -o testmainwindow_ui.py<br> from testmainwindow_ui import Ui_MainWindow # not nice here, but also not wrong<br> self.ui = Ui_MainWindow()<br> self.ui.setupUi(self)<br> else:<br> # importing "raw" QtCreator file<br> self.ui = uic.loadUi("testmainwindow.ui" ,self)<br><br> # One of the failings<br> self.ui.setWindowTitle("My Window is clean")<br><br>if __name__ == "__main__": # Die Hauptfunktion der Klasse<br> app = QApplication(sys.argv)<br> prog = window()<br> prog.show()<br> sys.exit(app.exec())</div><div><br></div><div><br></div><div>The testmainwindow.ui:</div><div><br></div><div><?xml version="1.0" encoding="UTF-8"?><br><ui version="4.0"><br> <class>MainWindow</class><br> <widget class="QMainWindow" name="MainWindow"><br> <property name="geometry"><br> <rect><br> <x>0</x><br> <y>0</y><br> <width>440</width><br> <height>310</height><br> </rect><br> </property><br> <property name="windowTitle"><br> <string>MainWindow</string><br> </property><br> <widget class="QWidget" name="centralwidget"><br> <widget class="QLabel" name="label_keyName"><br> <property name="geometry"><br> <rect><br> <x>110</x><br> <y>80</y><br> <width>43</width><br> <height>13</height><br> </rect><br> </property><br> <property name="text"><br> <string>Key:</string><br> </property><br> </widget><br> <widget class="QLabel" name="label"><br> <property name="geometry"><br> <rect><br> <x>50</x><br> <y>20</y><br> <width>43</width><br> <height>13</height><br> </rect><br> </property><br> <property name="text"><br> <string>Source:</string><br> </property><br> </widget><br> <widget class="QPushButton" name="pushButton_chooseFile"><br> <property name="geometry"><br> <rect><br> <x>350</x><br> <y>20</y><br> <width>80</width><br> <height>20</height><br> </rect><br> </property><br> <property name="text"><br> <string>PushButton</string><br> </property><br> </widget><br> <widget class="QLabel" name="label_2"><br> <property name="geometry"><br> <rect><br> <x>50</x><br> <y>50</y><br> <width>43</width><br> <height>13</height><br> </rect><br> </property><br> <property name="text"><br> <string>Sheets:</string><br> </property><br> </widget><br> <widget class="QDialogButtonBox" name="buttonBox_exit"><br> <property name="geometry"><br> <rect><br> <x>70</x><br> <y>240</y><br> <width>341</width><br> <height>32</height><br> </rect><br> </property><br> <property name="orientation"><br> <enum>Qt::Horizontal</enum><br> </property><br> <property name="standardButtons"><br> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set><br> </property><br> </widget><br> <widget class="QListWidget" name="listWidget_headers"><br> <property name="geometry"><br> <rect><br> <x>250</x><br> <y>100</y><br> <width>151</width><br> <height>141</height><br> </rect><br> </property><br> </widget><br> <widget class="QLabel" name="label_Headers"><br> <property name="geometry"><br> <rect><br> <x>250</x><br> <y>80</y><br> <width>43</width><br> <height>13</height><br> </rect><br> </property><br> <property name="text"><br> <string>Fields:</string><br> </property><br> </widget><br> <widget class="QLineEdit" name="lineEdit_fileName"><br> <property name="geometry"><br> <rect><br> <x>110</x><br> <y>20</y><br> <width>231</width><br> <height>20</height><br> </rect><br> </property><br> </widget><br> <widget class="QListWidget" name="listWidget_keys"><br> <property name="geometry"><br> <rect><br> <x>110</x><br> <y>100</y><br> <width>131</width><br> <height>141</height><br> </rect><br> </property><br> </widget><br> <widget class="QComboBox" name="comboBox_chooseSheet"><br> <property name="geometry"><br> <rect><br> <x>110</x><br> <y>50</y><br> <width>231</width><br> <height>22</height><br> </rect><br> </property><br> </widget><br> </widget><br> <widget class="QMenuBar" name="menubar"><br> <property name="geometry"><br> <rect><br> <x>0</x><br> <y>0</y><br> <width>440</width><br> <height>19</height><br> </rect><br> </property><br> </widget><br> <widget class="QStatusBar" name="statusbar"/><br> </widget><br> <resources/><br> <connections/><br></ui><br></div><div><br></div><div>And the testmainwindow_ui.py:</div><div><br></div><div># -*- coding: utf-8 -*-<br><br># Form implementation generated from reading ui file 'testmainwindow.ui'<br>#<br># Created by: PyQt5 UI code generator 5.12<br>#<br># WARNING! All changes made in this file will be lost!<br><br>from PyQt5 import QtCore, QtGui, QtWidgets<br><br><br>class Ui_MainWindow(object):<br> def setupUi(self, MainWindow):<br> MainWindow.setObjectName("MainWindow")<br> MainWindow.resize(440, 310)<br> self.centralwidget = QtWidgets.QWidget(MainWindow)<br> self.centralwidget.setObjectName("centralwidget")<br> self.label_keyName = QtWidgets.QLabel(self.centralwidget)<br> self.label_keyName.setGeometry(QtCore.QRect(110, 80, 43, 13))<br> self.label_keyName.setObjectName("label_keyName")<br> self.label = QtWidgets.QLabel(self.centralwidget)<br> self.label.setGeometry(QtCore.QRect(50, 20, 43, 13))<br> self.label.setObjectName("label")<br> self.pushButton_chooseFile = QtWidgets.QPushButton(self.centralwidget)<br> self.pushButton_chooseFile.setGeometry(QtCore.QRect(350, 20, 80, 20))<br> self.pushButton_chooseFile.setObjectName("pushButton_chooseFile")<br> self.label_2 = QtWidgets.QLabel(self.centralwidget)<br> self.label_2.setGeometry(QtCore.QRect(50, 50, 43, 13))<br> self.label_2.setObjectName("label_2")<br> self.buttonBox_exit = QtWidgets.QDialogButtonBox(self.centralwidget)<br> self.buttonBox_exit.setGeometry(QtCore.QRect(70, 240, 341, 32))<br> self.buttonBox_exit.setOrientation(QtCore.Qt.Horizontal)<br> self.buttonBox_exit.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)<br> self.buttonBox_exit.setObjectName("buttonBox_exit")<br> self.listWidget_headers = QtWidgets.QListWidget(self.centralwidget)<br> self.listWidget_headers.setGeometry(QtCore.QRect(250, 100, 151, 141))<br> self.listWidget_headers.setObjectName("listWidget_headers")<br> self.label_Headers = QtWidgets.QLabel(self.centralwidget)<br> self.label_Headers.setGeometry(QtCore.QRect(250, 80, 43, 13))<br> self.label_Headers.setObjectName("label_Headers")<br> self.lineEdit_fileName = QtWidgets.QLineEdit(self.centralwidget)<br> self.lineEdit_fileName.setGeometry(QtCore.QRect(110, 20, 231, 20))<br> self.lineEdit_fileName.setObjectName("lineEdit_fileName")<br> self.listWidget_keys = QtWidgets.QListWidget(self.centralwidget)<br> self.listWidget_keys.setGeometry(QtCore.QRect(110, 100, 131, 141))<br> self.listWidget_keys.setObjectName("listWidget_keys")<br> self.comboBox_chooseSheet = QtWidgets.QComboBox(self.centralwidget)<br> self.comboBox_chooseSheet.setGeometry(QtCore.QRect(110, 50, 231, 22))<br> self.comboBox_chooseSheet.setObjectName("comboBox_chooseSheet")<br> MainWindow.setCentralWidget(self.centralwidget)<br> self.menubar = QtWidgets.QMenuBar(MainWindow)<br> self.menubar.setGeometry(QtCore.QRect(0, 0, 440, 19))<br> self.menubar.setObjectName("menubar")<br> MainWindow.setMenuBar(self.menubar)<br> self.statusbar = QtWidgets.QStatusBar(MainWindow)<br> self.statusbar.setObjectName("statusbar")<br> MainWindow.setStatusBar(self.statusbar)<br><br> self.retranslateUi(MainWindow)<br> QtCore.QMetaObject.connectSlotsByName(MainWindow)<br><br> def retranslateUi(self, MainWindow):<br> _translate = QtCore.QCoreApplication.translate<br> MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))<br> self.label_keyName.setText(_translate("MainWindow", "Key:"))<br> self.label.setText(_translate("MainWindow", "Source:"))<br> self.pushButton_chooseFile.setText(_translate("MainWindow", "PushButton"))<br> self.label_2.setText(_translate("MainWindow", "Sheets:"))<br> self.label_Headers.setText(_translate("MainWindow", "Fields:"))</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>
</body></html>