Python——Pyqt5(界面)——基本设置

时间:2021-09-12 03:36:48

一、Pycharm外加设置

  设置扩展工具

     1.Qt Design(图形界面)

      Program:工程目录\venv\Lib\site-packages\pyqt5-tools\designer.exe 
      Arguments:$FileDir$\$FileName$ 
      Working directory:$FileDir$

     2.Pyuci5(ui转py)

      Program:工程目录\venv\Scripts\pyuic5.exe 
      Arguments:$FileName$ -o $FileNameWithoutExtension$.py 
      Working directory:$FileDir$

     3.Pyrcc5

      Program:工程目录\venv\Scripts\pyrcc5.exe 
      Arguments:$FileName$ -o $FileNameWithoutExtension$.py 
      Working directory:$FileDir$

二、将ui转换成py

  (1)利用cmd命令,跳转到ui所在目录

  (2)使用命令:  pyuic5 -o main.py 1.ui

三、添加代码,显示内容

  (1)引用 sys包: import sys

  (2)程序尾部添加一下内容

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())