In my script I sometimes call my ErrorWindow
class to show an error message. This creates an empty tkinter
window and a messagebox
error window. I either only want the messagebox
window, or I want the tkinter
window to close automatically when I close the error window.
I've tried two pieces of code:
class ErrorWindow:
def __init__(self,error_message):
self.error_window = tk.Tk()
messagebox.showerror("ERROR",error_message,command=self.close)
self.error_window.protocol("WM_DELETE_WINDOW", self.close)
self.error_window.mainloop()
def close(self):
self.error_window.destroy()
.
class ErrorWindow:
def __init__(self,error_message):
messagebox.showerror("ERROR",error_message) #automatically creates a tk window too
But even with the second one, the tkinter
window remains after I close the messagebox
.
How can I program the class so that I only have to press a button (either Ok
or the X
in the top right of a window) once to close all windows (whether that is one or two)?