I have 2 methods in my titlebar application, both hiding and showing a toplevel window I have to make to keep a taskbar icon, and they are called on tkinter’s and events. I have the problem that when called, each method is for whatever reason, being called 6 times. My on_restore method is additionally being called once right after on_minimize is being called.
Here’s my code:
class titlebar(tk.Frame):
def __init__(self, parent, app_title, bg_color, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.parent = parent
self.parent.overrideredirect(True)
self.top = tk.Toplevel(parent)
self.top.attributes("-alpha", 0)
self.app_title = app_title
self.bg_color = bg_color
self.parent.bind("<Unmap>", self.on_minimize)
self.parent.bind("<Map>", self.on_restore)
def on_minimize(self, event):
print("minimize")
self.top.deiconify()
def on_restore(self, event):
print("restore")
self.top.iconify()
I’ll just include these methods as well, just in case they are part of the problem:
def restore_window(self, event):
self.parent.overrideredirect(True)
self.parent.attributes('-alpha', 1)
self.parent.deiconify()
self.parent.attributes('-topmost', 1)
def minimize_window(self):
self.parent.attributes('-alpha', 0)
self.parent.overrideredirect(False)
self.parent.iconify()