pyqt 生成ui后,python增加代码

# Form implementation generated from reading ui file 'weather.ui'
#
# Created by: PyQt6 UI code generator 6.4.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtWidgets import QApplication, QWidget


class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(400, 300)
        Form.setBaseSize(QtCore.QSize(400, 350))
        self.label = QtWidgets.QLabel(parent=Form)
        self.label.setGeometry(QtCore.QRect(130, 80, 151, 61))
        self.label.setTextFormat(QtCore.Qt.TextFormat.PlainText)
        self.label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
        self.label.setObjectName("label")

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

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "四川天气预报"))
        self.label.setText(_translate("Form", "今天天气不错"))

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = QWidget()

    ui = Ui_Form()
    ui.setupUi(w)
    w.show()
    sys.exit(app.exec())

 if后面是增加的,前面是design生成的

posted @ 2025-06-10 20:43  brady-wang  阅读(10)  评论(0)    收藏  举报