# in pyqt5 it needs to be PyQt5.QtWidgets
msg=QMessageBox() # create an instance of it
msg.setIcon(QMessageBox.Information) # set icon
msg.setText("This is a message box") # set text
msg.setInformativeText("This is additional information") # set information under the main text
msg.setWindowTitle("MessageBox demo") # set title
msg.setDetailedText("The details are as follows:") # a button for more details will add in
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) # type of buttons associated
msg.buttonClicked.connect(myfunc) # connect clicked signal
return_value =msg.exec_() # get the return value
print("value of pressed message box button:", str(return_value)) # print result
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class AppForm(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.create_main_frame()
def create_main_frame(self):
page = QWidget()
self.button = QPushButton('joy', page)
self.edit1 = QLineEdit()
self.edit2 = QLineEdit()
vbox1 = QVBoxLayout()
vbox1.addWidget(self.edit1)
vbox1.addWidget(self.edit2)
vbox1.addWidget(self.button)
page.setLayout(vbox1)
self.setCentralWidget(page)
self.connect(self.button, SIGNAL("clicked()"), self.clicked)
def clicked(self):
QMessageBox.about(self, "My message box", "Text1 = %s, Text2 = %s" % (
self.edit1.text(), self.edit2.text()))
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
form = AppForm()
form.show()
app.exec_()
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText("This is a message box")
msg.setInformativeText("This is additional information")
msg.setWindowTitle("MessageBox demo")
msg.setDetailedText("The details are as follows:")
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
msg.buttonClicked.connect(msgbtn)