ui转换为py文件后,在进行初始化没有问题,但是加载QMessageBox时报错。
from PySide6.QtWidgets import QApplication,QMessageBox,QMainWindow
from ui.patinfo_search import *
import sys
class UI(QMainWindow,Ui_Form):
def __init__(self,parent = None):
super(UI,self).__init__(parent)
# 子类继承了父类的所有属性和方法,父类属性自然会用父类方法来进行初始化
self.ui = Ui_Form() # 来自 patinfo_search.py 中的类。
self.ui.setupUi(self)
self.ui.button1.clicked.connect(self.yahoo)
self.ui.button2.clicked.connect(self.copy)
def yahoo(self):
print('button1 was be knocked')
QMessageBox.about(self.ui,'反馈结果','hello hello hello')
def copy(self):
print('button1 was be knocked')
info = self.ui.textedit1.toPlainText()
QMessageBox.about(self.ui,'复制结果',f'{info}')
if __name__ == '__main__':
app = QApplication(sys.argv)
uiui = UI()
uiui.show()
sys.exit(app.exec_())
py文件
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'patinfo_search.ui'
##
## Created by: Qt User Interface Compiler version 6.4.3
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QPlainTextEdit, QPushButton, QSizePolicy,
QWidget)
class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(737, 556)
self.button1 = QPushButton(Form)
self.button1.setObjectName(u"button1")
self.button1.setGeometry(QRect(490, 150, 81, 31))
self.button2 = QPushButton(Form)
self.button2.setObjectName(u"button2")
self.button2.setGeometry(QRect(490, 270, 81, 31))
self.textedit1 = QPlainTextEdit(Form)
self.textedit1.setObjectName(u"textedit1")
self.textedit1.setGeometry(QRect(120, 90, 291, 281))
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
# setupUi
def retranslateUi(self, Form):
Form.setWindowTitle(QCoreApplication.translate("Form", u"patinfo_search", None))
self.button1.setText(QCoreApplication.translate("Form", u"\u70b9\u51fb\u6d4b\u8bd5", None))
self.button2.setText(QCoreApplication.translate("Form", u"\u83b7\u53d6\u4fe1\u606f", None))
# retranslateUi
点击按钮后提示:
TypeError: 'PySide6.QtWidgets.QMessageBox.about' called with wrong argument types:
PySide6.QtWidgets.QMessageBox.about(Ui_Form, str, str)
Supported signatures:
PySide6.QtWidgets.QMessageBox.about(PySide6.QtWidgets.QWidget, str, str)