[PyQt] Creating a message box
Sergio Daniel Gomez
sergiogomez at tostado.com.ar
Tue Apr 7 13:04:06 BST 2009
klia escribió:
> Hey guys;
>
> i am totally new to pyqt
>
> My query is can some one give me an example that creates a button which will
> display a message box once it's clicked
>
> thank you
#!/usr/bin/python
# messagebox.py
import sys
from PyQt4 import QtGui
class MessageBox(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('message box')
def closeEvent(self, event):
reply = QtGui.QMessageBox.question(self, 'Message',
"Are you sure to quit?", QtGui.QMessageBox.Yes,
QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
event.accept()
else:
event.ignore()
app = QtGui.QApplication(sys.argv)
qb = MessageBox()
qb.show()
sys.exit(app.exec_())
The example is from here [0]. There are a class named QMessageBox [1],
see it for more options.
[0]http://zetcode.com/tutorials/pyqt4/firstprograms/
[1]http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qmessagebox.html
Regards.
Sergio D. Gómez
Tostado (Argentina)
More information about the PyQt
mailing list