Showing the error dialogs

Now that you understand how to use messagebox, error dialogs should be easy to implement. The Application.on_save() method already displays errors in the status bar; we just need to make this error display in an error message box as well by performing the following steps:

  1. First, we'll need to import it in application.py as follows:
from tkinter import messagebox
  1. Now, in the on_save() method after the check for errors, we'll set up the message for the error dialog. We'll make a bullet list of the fields with errors by joining them with "\n *". Unfortunately, messagebox doesn't support any sort of markup, so constructs like bullet lists need to be built manually using regular characters, as in the following:

Get Python GUI Programming with Tkinter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.