Copy Code code as follows:
#coding =utf-8
#对话框
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.EXEC_ ()