pyinstaller pyside2 qtdesigner
files:
.ui
.py
main.py
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>170</x>
<y>160</y>
<width>105</width>
<height>39</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QToolButton" name="toolButton">
<property name="geometry">
<rect>
<x>130</x>
<y>250</y>
<width>37</width>
<height>39</height>
</rect>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox">
<property name="geometry">
<rect>
<x>210</x>
<y>260</y>
<width>103</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>CheckBox</string>
</property>
</widget>
<widget class="QCommandLinkButton" name="commandLinkButton">
<property name="geometry">
<rect>
<x>190</x>
<y>350</y>
<width>201</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>CommandLinkButton</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>36</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
### .py file by using uic -g python <file>.ui > <file>.py
# -*- coding: utf-8 -*-
from PySide2.QtCore import * # type: ignore
from PySide2.QtGui import * # type: ignore
from PySide2.QtWidgets import * # type: ignore
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
if not MainWindow.objectName():
MainWindow.setObjectName(u"MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
self.pushButton = QPushButton(self.centralwidget)
self.pushButton.setObjectName(u"pushButton")
self.pushButton.setGeometry(QRect(170, 160, 105, 39))
self.toolButton = QToolButton(self.centralwidget)
self.toolButton.setObjectName(u"toolButton")
self.toolButton.setGeometry(QRect(130, 250, 37, 39))
self.checkBox = QCheckBox(self.centralwidget)
self.checkBox.setObjectName(u"checkBox")
self.checkBox.setGeometry(QRect(210, 260, 103, 27))
self.commandLinkButton = QCommandLinkButton(self.centralwidget)
self.commandLinkButton.setObjectName(u"commandLinkButton")
self.commandLinkButton.setGeometry(QRect(190, 350, 201, 41))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(MainWindow)
self.menubar.setObjectName(u"menubar")
self.menubar.setGeometry(QRect(0, 0, 800, 36))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QStatusBar(MainWindow)
self.statusbar.setObjectName(u"statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QMetaObject.connectSlotsByName(MainWindow)
# setupUi
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
self.pushButton.setText(QCoreApplication.translate("MainWindow", u"PushButton", None))
self.toolButton.setText(QCoreApplication.translate("MainWindow", u"...", None))
self.checkBox.setText(QCoreApplication.translate("MainWindow", u"CheckBox", None))
self.commandLinkButton.setText(QCoreApplication.translate("MainWindow", u"CommandLinkButton", None))
# retranslateUi
### main.py
import sys
from PySide2.QtWidgets import QApplication, QMainWindow
from PySide2.QtCore import *
from ui_mainwindow import Ui_MainWindow
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
`run by python main.py`
`pyinstaller -F main.py`