python下.ui转为.py文件,并用另一.py调用显示
1、在pycharm->tools->External tools -> QTdesigner ,运行QTdesigner
生成界面。
2、重要步骤1: pycharm 工程里找到 UItest.ui 右键,->External tools ->pyuic
点击,生成 UItest.py 文件。生成后工程里能看到!
3、重要步骤2:另建一个新的.py 加入
import sys
from UItest import Ui_MainWindow
from PyQt5 import QtWidgets
class 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文件里 注释掉 MainWindow开头的三句
# MainWindow.setCentralWidget(self.centralwidget)# MainWindow.setMenuBar(self.menubar)# MainWindow.setStatusBar(self.statusbar)
5、运行刚才新建的.py
OK!
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:20
阅读量:166
阅读量:78
阅读量:42
阅读量:104