pyqt4教程之messagebox使用示例分享

yipeiwu_com4年前Python基础

复制代码 代码如下:

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

相关文章

tensorflow实现在函数中用tf.Print输出中间值

tensorflow实现在函数中用tf.Print输出中间值

tensorflow由于其基于静态图的模式,导致写代码的时候很难调试,除了用官方的调试工具外,最直接的方法就是把中间结果输出出来查看,然而,直接用print函数只能输出tensor变量的...

python的range和linspace使用详解

在python中要产生一个数字序列,最快的方法就是使用range和linspace函数,但是这两者不太一样,但总的来说实现的效果是一致的,都能获取一个数字序列。 range range一...

Python脚本实现格式化css文件

最近研究研究了css,少不了去网上分析一下别人的网页, 但很多网站的css文件都是要么写在一行,要么一个换行都没有,看起来极其痛苦,所以写一个脚本转换一下,转换为比较有可读性的格式。下面...

python3实现读取chrome浏览器cookie

好几年前我在做一些自动化的脚本时,脑子里也闪过这样的想法:能不能直接把浏览器的cookies取出来用呢? 直到昨天看到代码《python模拟发送动弹》,想起来当年我也曾经有类似的想法没能...

Python 类的私有属性和私有方法实例分析

本文实例讲述了Python 类的私有属性和私有方法。分享给大家供大家参考,具体如下: xx:公有变量 _xx:公有变量或方法,不能通过import导入其他模块(只有模块内部使用)。类对象...