ui转为py文件后,调用方法

一.zhongke.py


from PyQt5 import QtCore, QtGui, QtWidgets

from poseUI import Ui_Form
import sys
class ZhongKe(QtWidgets.QMainWindow, Ui_Form):
    def __init__(self):
        super(ZhongKe,self).__init__()
        self.setupUi(self)
if __name__ == '__main__':

    from PyQt5 import QtCore
    # QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)  # 自适应分辨率
    app = QtWidgets.QApplication(sys.argv)
    ui = ZhongKe()
    ui.show()
    sys.exit(app.exec_())

二. poseUi.py(pose.ui——>poseUi.py)
命令端输入 pyuic5 -o poseUi.py pose.ui

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1164, 836)
        self.pushButton = QtWidgets.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(650, 470, 75, 24))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(Form)
        self.pushButton_2.setGeometry(QtCore.QRect(530, 470, 75, 24))
        self.pushButton_2.setObjectName("pushButton_2")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.pushButton.setText(_translate("Form", "PushButton"))

在这里插入图片描述
三. ui无法调用鼠标事件解决办法
这是导入ui文件的方式不对

from PyQt5 import QtWidgets, uic
import sys
 
form_class = uic.loadUiType('new.ui')[0]
class Ui(QtWidgets.QMainWindow, form_class):
    def __init__(self):
        super(Ui, self).__init__()
        self.setupUi(self)
 
 if __name__=='__main__':
	app = QtWidgets.QApplication(sys.argv)
	window = Ui()
	window.show()
	sys.exit(app.exec_())

四.调用成功后界面显示不全
可能是因为加了分页,取消即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值