from tkinter import * root = Tk() root.geometry("200x100") class tk_(): def __init__(self): Button(text="press").pack() root.bind('<Unmap>', self.curtail_win) def curtail_win(self,event): print("Error") def bind_all(self): print("Bind") tk = tk_() root.mainloop() 

For some reason, the curtail_win function curtail_win called as many times as there are widgets on it + window itself

Conclusion:

 Error Error 

The function was called 2 times, ie the Window + Button = 2 times the function call


 from tkinter import * root = Tk() root.geometry("200x100") class tk_(): def __init__(self): Button(text="Press").pack() Button(text="New").pack() root.bind('<Unmap>', self.curtail_win) def curtail_win(self,event): print("Error") def bind_all(self): print("Bind") tk = tk_() root.mainloop() 

Here already 3 times Conclusion:

 Error Error Error 

Here already: Window + Button + Button = 3

  • @jfs Understand the problem? - Оаав ярыыва

1 answer 1

The event has a widget attribute that shows what it refers to. For example, if self is your window, you can immediately return if the wrong widget is specified:

 def on_unmap(self, event): if event.widget is not self: return