QTCreator+Python

  1. 下载QT5 https://www.qt.io   默认安装,QT Creator(默认包含),如果只使用python开发的话,只需要选择MinGW.
  2. 添加 C:\QT\5.12.0\mingw73_64\bin 到环境变量Path中
  3. 使用 QT Creator 创建 QT-> QT设计师界面类->不要选main window. 编辑完后保存全部
  4. 把UI文件编译成py文件.   C:\Anaconda3\python.exe -m PyQt5.uic.pyuic -o dialog.py dialog.ui (把 dialog.ui 编译成dialog.py )
  5. 打开pycharm在py文件末尾添加
    if __name__ == "__main__":
        app = QtWidgets.QApplication(sys.argv)
        MainWindow = QtWidgets.QMainWindow()
        ui = Ui_Dialog()
        ui.setupUi(MainWindow)
        MainWindow.show()
        sys.exit(app.exec_())

    运行就能看到界面了

  6. 自动编译文件夹下所有.UI文件
    import os
    ui_files=[]
    
    def getUIFiles():
        dir = os.getcwd()
        for root, dirs, files in os.walk(dir):
            for name in files:
                extension=os.path.splitext(name)[1]
                if extension=='.ui':
                    ui_files.append(os.path.join(root,name))
    
    def transPYFiles(file):
        return os.path.splitext(file)[0]+".py"
    
    def runCMD():
        if len(ui_files):
            for file in ui_files:
                py_file=transPYFiles(file)
                cmd="C:\Anaconda3\python.exe -m PyQt5.uic.pyuic -o {} {}".format(py_file,file)
                os.system(cmd)
    
    getUIFiles()
    runCMD()

     

转载于:https://www.cnblogs.com/xuyuchen/p/10202421.html

你可能感兴趣的:(QTCreator+Python)