File "E:\python\学生信息管理系统\student.py", line 386, in change_password QtWidgets.QMessageBox.information(self, '提示', '密码修改成功') TypeError: information(parent: QWidget, title: str, text: str, buttons: Union[QMessag eBox.StandardButtons, QMessageBox.StandardButton] = QMessageBox.Ok, defaultButton: QM essageBox.StandardButton = QMessageBox.NoButton): argument 1 has unexpected type 'Ui_ MainWindow'怎么解决
时间: 2024-03-27 16:39:52 浏览: 129
这个错误提示意味着 `QtWidgets.QMessageBox.information()` 函数的第一个参数应该是一个 `QtWidgets.QWidget` 对象,但是你传递了一个 `Ui_MainWindow` 对象,这是不合法的。
一个解决方法是,在 `change_password()` 函数中,将 `self` 替换为 `self.parent()`,这将返回父级窗口的 `QtWidgets.QWidget` 对象。修改后的代码如下:
```
def change_password(self):
old_password = self.lineEdit_11.text()
new_password = self.lineEdit_12.text()
confirm_password = self.lineEdit_13.text()
# 验证旧密码是否正确
if old_password != self.password:
QtWidgets.QMessageBox.warning(self.parent(), '警告', '旧密码错误')
return
# 验证新密码和确认密码是否一致
if new_password != confirm_password:
QtWidgets.QMessageBox.warning(self.parent(), '警告', '新密码和确认密码不一致')
return
self.password = new_password
QtWidgets.QMessageBox.information(self.parent(), '提示', '密码修改成功')
```
注意,我们使用 `self.parent()` 代替了 `self`,并且将其作为第一个参数传递给了 `QtWidgets.QMessageBox.warning()` 和 `QtWidgets.QMessageBox.information()` 函数。
阅读全文