PyQt5中为我们提供了很多默认信息框QMessageBox,注意为方便使用需要导入模块。
(QMessageBox对话框包含类型只是图标不同其他无太大差别)
- QMessageBox.information 信息框
- QMessageBox.question 问答框
- QMessageBox.warning 警告
- QMessageBox.ctitical危险
- QMessageBox.about 关于
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMessageBox
class MyWindow(QtWidgets.QWidget):
def __init__(self):
super(MyWindow,self).__init__()
self.myButton = QtWidgets.QPushButton(self)
self.myButton.setObjectName("myButton")
self.myButton.setText("Test")
self.myButton.clicked.connect(self.msg)
def msg(self):
reply = QMessageBox.information(self, "标题", "消息", QMessageBox.Yes | QMessageBox.No)
if __name__=="__main__":
import sys
app=QtWidgets.QApplication(sys.argv)
myshow=MyWindow()
myshow.show()
sys.exit(app.exec_())