code: def onCancelButton(self, event):
          
          if self.grid.changes:
              dlg1 = wx.MessageDialog(self, caption="Message:",
                                      message="Are you sure you want to exit this grid?\nYour changes will not be saved.\n ",
                                      style=wx.OK|wx.CANCEL)
              result = dlg1.ShowModal()
              if result == wx.ID_OK:
                  dlg1.Destroy()
                  self.Destroy()
          else:
              self.Destroy()
          if self.main_frame:
              self.main_frame.Show()
              self.main_frame.Raise()
docs: Quit grid with warning if unsaved changes present