Installation configuration process for PyQt5 an instance of the display window after converting an ui file to an py file

  • 2021-06-29 11:19:25
  • OfStack

PyQt5 Installation

Enter pip install PyQt5 under cmd to complete the PyQt5 installation.

Once the installation is complete, you can see it in the python installation directory

Configure PyCharm

PyCharm is configured to open qt designer within Pycharm, generate qt files, and then convert the qt files into software files in the python language.

Open Pycharm and press the image below

After opening Extrernal Tools, click on the green + above to add Tools

Name: Custom

Program: Point to designer.exe inside the above installation PyQt5-tools

Work directory: Use variable $FileDir$

Then create one more "PyUIC", which is mainly used to convert the Qt interface into py code.

Parameter configuration: -m PyQt5.uic.pyuic $FileName$-o $FileNameWithoutExtension$.py

The resulting ui cannot be run directly after it has been converted to an py file. Add the following code to display the window.


import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
if __name__ == '__main__':
  app = QApplication(sys.argv)
  MainWindow = QMainWindow()
  ui = Ui_MainWindow()
  ui.setupUi(MainWindow)
  MainWindow.show()
  sys.exit(app.exec_())

Related articles: