Preventing form submission on error

The final step in preventing errors from getting into our CSV file is to stop the application from saving if the form has known errors. Let's perform the following steps to do this:

  1. The first step in implementing this is to provide a way for the Application object (which handles saving the data) to retrieve the error status from the DataRecordForm object.
  2. At the end of the DataRecordForm class, add the following method:
    def get_errors(self):        """Get a list of field errors in the form"""        errors = {}        for key, widget in self.inputs.items():            if hasattr(widget.input, 'trigger_focusout_validation'):                widget.input.trigger_focusout_validation()            if widget.error.get():                errors[key] = widget.error.get() return errors ...

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.