1import sys
2from PyQt4.QtGui import *
3from PyQt4.QtCore import *
4
5def window():
6 app = QApplication(sys.argv)
7 w = QWidget()
8 b = QPushButton(w)
9 b.setText("Show message!")
10
11 b.move(50,50)
12 b.clicked.connect(showdialog)
13 w.setWindowTitle("PyQt Dialog demo")
14 w.show()
15 sys.exit(app.exec_())
16
17def showdialog():
18 msg = QMessageBox()
19 msg.setIcon(QMessageBox.Information)
20
21 msg.setText("This is a message box")
22 msg.setInformativeText("This is additional information")
23 msg.setWindowTitle("MessageBox demo")
24 msg.setDetailedText("The details are as follows:")
25 msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
26 msg.buttonClicked.connect(msgbtn)
27
28 retval = msg.exec_()
29 print "value of pressed message box button:", retval
30
31def msgbtn(i):
32 print "Button pressed is:",i.text()
33
34if __name__ == '__main__':
35 window()
1# Question
2# Information
3# Warning
4# Critical
5
6# Example:
7msg.setIcon(QMessageBox.Information)