pyqt5 messagebox
Python hosting: Host, run, and code Python in the cloud!
In this article you will learn how to create a PyQt5 messagebox:
A message box is a class to show a small dialog with an ordinary message, an information message, or a question and it can confirm one or two choices.
A message box can be created using the class QMessageBox. This class provides a modal dialog with a short text, an icon, and buttons. The class has method show() display a message box and return immediately.
To show a messagebox we need to import QMessageBox.
|
We use the method QMessageBox.question() to display the messagebox.
Related course: Create GUI Apps with PyQt5
PyQt5 messagebox code
Copy the code below to display a messagebox.
|
More buttons for a messagebox
Take into account we use QMessageBox.Yes and QMessageBox.No. We can easily add other options:
|
The available buttons are:
Overview | ||
QMessageBox.Cancel | QMessageBox.Ok | QMessageBox.Help |
QMessageBox.Open | QMessageBox.Save | QMessageBox.SaveAll |
QMessageBox.Discard | QMessageBox.Close | QMessageBox.Apply | QMessageBox.Reset | QMessageBox.Yes | QMessageBox.YesToAll |
QMessageBox.No | QMessageBox.NoToAll | QMessageBox.NoButton |
QMessageBox.RestoreDefaults | QMessageBox.Abort | QMessageBox.Retry |
QMessageBox.Ignore |
If you are new to programming Python PyQt, I highly recommend this book.
Leave a Reply: