1、在pycharm->tools->External tools -> QTdesigner ,运行QTdesigner生成界面。
2、重要步骤1: pycharm 工程里找到UItest.ui 陴查哉厥右键,->External tools ->pyuic点击,生成 UItest.py 文件。生成后工程里能看到!
3、重要步骤2:另建一个新的.py 加入 import sysfrom UItest import Ui_MainWindowfrom P烤恤鹇灭yQt5 import QtWidgetsclass mywindow(QtWidgets.QWidget, Ui_MainWindow): # 这个地方要注意Ui_MainWindow def __init__(self): super(mywindow, self).__init__() self.setupUi(self) #。。。加自己的函数等if __name__=="__main__": app=QtWidgets.QApplication(sys.argv) myshow=mywindow() myshow.show()#显示 sys.exit(app.exec_())
4、重要步骤3: 在.ui文件生成那个的.py文件里 注释掉Ma坡纠课柩inWindow开头的三句# MainWindow.setCentralWidget(self.centralwidget)# MainWindow.setMenuBar(self.menubar)# MainWindow.setStatusBar(self.statusbar)
5、运行刚才新建的.pyOK!