I am currently working on a homebanking app as a personal project. Learning and stuff
It contains a main module with a window and buttons with several functions (such as transferring money between accounts, paying bills, etc.). When you click a button, it disables all the main window widgets, creates a toplevel linked to the main window and finishes off with opening a new module that deals with the functions needed. This was perhaps not my brightest idea, but I did it so I could divide my code and not have it all in one file, to improve the readability and cleanliness of the code (open to suggestions btw)
When a toplevel is destroyed, a .bind functions calls another function that rehabilitates the main module widgets and updates the info based on the changes made (if any). The problem comes when you try to destroy a toplevel for a second time, since the .bind function doesn't seem to be called at all. Why could this be?
This here is the stuff the transference button does
self.disable()
windowTransfer = Toplevel(self.windowHomeBanking)
windowTransfer.bind("<Destroy>", self.closed_window)
from transfer import Transfer
tf = Transfer(windowTransfer, self.id,
self.userFile, self.data, self.userList)
And this here is the closed_window function (don't think it's important since it doesn't get called at all the second time)
if str(event.widget) != ".!toplevel": # (to avoid calling the function an innecessary number of times)
return
for item in self.windowHomeBanking.winfo_children():
if str(item) != ".!toplevel":
item.config(state = NORMAL)
if str(event) == "<Destroy event>" and str(event.widget) == ".!toplevel":
self.update_data()
You should not be testing the name of the window since the second window will not necessarily have the same name as the first. If you want to make sure that the code only runs for the toplevel and not its children you can do this:
if event.widget != event.widget.winfo_toplevel():
return
winfo_toplevel
returns the window associated with the event. For every child as well as the window itself, the result will be the window object.