0

I´m trying to react with an exception when my tkinter window is closed with X, so that I can handle some database things in main before leaving. The Exception get´s thrown but not propagated - is there any reason for that? I can help myself with a global class Variable... but i wonder why this is like that.

class GuiBase(GuiConst):
    def __init__(self):
        super().__init__()

        self.root = Tk()  # create root window
.
.
.
        self.root.protocol('WM_DELETE_WINDOW', self.on_closing)

    def on_closing(self):
        if messagebox.askokcancel("Quit", "Programm beenden?"):
            self.root.destroy()
            raise exception.WindowClosedWithX

I expected the Exception beeing propagiated, i can see it is thrown but not propagiated

JRiggles
  • 4,847
  • 1
  • 12
  • 27
  • 1
    The exception is propagated from `GuiBase.on_close` to `tkinter`'s internal methods (which you aren't supposed to mess with) to the somewhere in `mainloop()` which prints the error. If you want to catch errors that happen in `tkinter` callbacks look at [this](https://stackoverflow.com/a/6667069/11106801) – TheLizzard Nov 20 '22 at 17:16

0 Answers0