This article mainly introduces the messagebox example of pyqt4. For more information, see
The code is as follows:
# Coding = UTF-8
# Dialog box
Import sys
From PyQt4 import QtGui, QtCore
Class Window (QtGui. QWidget ):
Def _ init _ (self ):
Super (Window, self). _ init __()
Self. setWindowTitle ("hello ")
Self. resize (500,500)
Gridlayout = QtGui. QGridLayout ()
Self. AboutButton = QtGui. QPushButton ("About ")
Gridlayout. addWidget (self. AboutButton, 0, 0)
Self. AboutQtButton = QtGui. QPushButton ("AboutQt ")
Gridlayout. addWidget (self. AboutQtButton, 0, 1)
Self. CriticalButton = QtGui. QPushButton ("CriticalButton ")
Gridlayout. addWidget (self. CriticalButton, 1, 0)
Self. InfoButton = QtGui. QPushButton ("Info ")
Gridlayout. addWidget (self. InfoButton, 1, 1)
Self. QuestionButton = QtGui. QPushButton ("Question ")
Gridlayout. addWidget (self. QuestionButton, 2, 0)
Self. WarningButton = QtGui. QPushButton ("Warning ")
Gridlayout. addWidget (self. WarningButton, 2, 1)
Spacer = QtGui. QSpacerItem (200, 80)
Gridlayout. addItem (spacer, 3, 1, 1, 5)
Self. setLayout (gridlayout)
Self. connect (self. AboutButton, QtCore. SIGNAL ('clicked () '), self. OnAboutButton)
Self. connect (self. AboutQtButton, QtCore. SIGNAL ('clicked () '), self. OnAboutQtButton)
Self. connect (self. CriticalButton, QtCore. SIGNAL ('clicked () '), self. OnCriticalButton)
Self. connect (self. InfoButton, QtCore. SIGNAL ('clicked () '), self. OnInfoButton)
Self. connect (self. QuestionButton, QtCore. SIGNAL ('clicked () '), self. OnQuestionButton)
Self. connect (self. WarningButton, QtCore. SIGNAL ('clicked () '), self. OnWarningButton)
Def OnAboutButton (self ):
QtGui. QMessageBox. about (self, 'pyqt ', "About ")
Def OnAboutQtButton (self ):
QtGui. QMessageBox. aboutQt (self, "PyQt ")
Def OnCriticalButton (self ):
R = QtGui. QMessageBox. critical (self, "PyQT", "CriticalButton", QtGui. QMessageBox. Abort,
QtGui. QMessageBox. Retry, QtGui. QMessageBox. Ignore)
If r = QtGui. QMessageBox. Abort:
Self. setWindowTitle ("Abort ")
Elif r = QtGui. QMessageBox. Retry:
Self. setWindowTitle ("Retry ")
Elif r = QtGui. QMessageBox. Ignore:
Self. setWindowTitle ("Ignore ")
Else:
Pass
Def OnInfoButton (self ):
QtGui. QMessageBox. information (self, "Pyqt", "information ")
Def OnQuestionButton (self ):
R = QtGui. QMessageBox. question (self, "PyQt", "Question", QtGui. QMessageBox. Yes, QtGui. QMessageBox. No, QtGui. QMessageBox. Cancel)
Def OnWarningButton (self ):
R = QtGui. QMessageBox. warning (self, "PyQT", "warning", QtGui. QMessageBox. Yes, QtGui. QMessageBox. No)
App = QtGui. QApplication (sys. argv)
Win = Window ()
Win. show ()
App.exe c _()