tareq1988

Message Box in PyQt

Sep 29th, 2011
1,174
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. #messagebox.py
  4.  
  5. import sys
  6. from PyQt4 import QtGui, QtCore
  7.  
  8. class MessageBox(QtGui.QWidget):
  9. """ Class doc """
  10.  
  11.     def __init__ (self, parent=None):
  12.         """ Class initialiser """
  13.         QtGui.QWidget.__init__(self, parent)
  14.  
  15.         self.setGeometry(300, 300, 250, 150)
  16.         self.setWindowTitle('Message Box')
  17.  
  18.     def closeEvent(self, event):
  19.         """ Function doc """
  20.         reply = QtGui.QMessageBox.question(self,  'Message',  'Are you sure to quit?',  QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
  21.  
  22.         if reply == QtGui.QMessageBox.Yes:
  23.             event.accept()
  24.         else:
  25.             event.ignore()
  26.  
  27. app = QtGui.QApplication(sys.argv)
  28. qb = MessageBox()
  29. qb.show()
  30. sys.exit(app.exec_())
  31.  
  32.  
RAW Paste Data