PyQt5写一个QDialog中含有QmessageBox的代码
时间: 2024-05-05 08:19:06 浏览: 18
好的,请稍等,我来给您提供一个PyQt5编写QDialog并包含QMessageBox的示例代码:
```python
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox, QPushButton
class MyDialog(QDialog):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 设置窗口标题
self.setWindowTitle('QDialog with QMessageBox')
# 创建按钮并绑定事件
btn = QPushButton('Click me', self)
btn.clicked.connect(self.showMessage)
def showMessage(self):
# 创建消息框
msgBox = QMessageBox(self)
msgBox.setText('Hello, World!')
msgBox.exec_()
if __name__ == '__main__':
app = QApplication([])
dialog = MyDialog()
dialog.show()
app.exec_()
```
希望可以帮助您解决问题!如有任何疑问,欢迎随时向我询问。