Pyqt4 tutorial-messagebox example

Source: Internet
Author: User
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 _()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.