I have an tkinter application that can can open child forms when I click a button.
def open_new_form():
child_form = ChildForm()
list_of_children_form.append(child_form)
child_form.show()
How do I keep track of all the forms that was created by the main app ?
I would like to be able to count the number of child forms that are active (not closed). I can use a counter that increments every time I create a new child form , but how do I update the counter if a child form is closed/destroyed.
Update 1: I have a list to record the created child forms (see updated code above) . How do I track the state (closed or not) of those in the list?
What I wanted to do:
- My main window opens 4 child_forms (c1, c2, c3, c4 )
- It created a list of form [c1, c2, c3, c4]
- I closed child_form c1, how can I inform the main window that I closed c1 so that it can remove it from the list.
Update 2: Tried suggestion from [furas]. I added a method delete_child() on the main form, passed the parent form to the child form.
def __init__(self, parent):
self._parent = parent
def _on_form_closing(self):
self._parent.delete_child()
self.child_form.destroy()
However, i get this error :
AttributeError: '_tkinter.tkapp' object has no attribute 'delete_child'