欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

pyqt4教程之messagebox使用示例分享

程序员文章站 2023-11-04 22:32:46
复制代码 代码如下:#coding=utf-8#对话框import sysfrom pyqt4 import qtgui, qtcoreclass window( qtgu...

复制代码 代码如下:

#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_()