You may want to restructure your code. The following sample application demonstrates how to open a dialog for text entry and prevent closure of the main window when the dialog finishes executing:
from tkinter import Label, NoDefaultRoot, Tk
from tkinter.font import Font
from tkinter.simpledialog import askstring
def main():
NoDefaultRoot()
root = Tk()
root.title('Demonstration')
root.resizable(False, False)
Label(root, font=Font(root, size=24)).grid()
root.after_idle(animate_label, root, 3)
root.mainloop()
def animate_label(root, time_left):
label = get_any_child(root, Label)
label['text'] = 'Opening a dialog in {} ...'.format(max(time_left, 0))
if time_left > 0:
root.after(1000, animate_label, root, time_left - 1)
else:
root.after_idle(open_dialog, root)
def get_any_child(widget, kind):
return get_any(get_children(widget), kind)
def get_children(widget):
return iter(widget.children.values())
def get_any(iterable, kind):
return next(item for item in iterable if isinstance(item, kind))
def open_dialog(root):
answer = askstring('Text Entry', 'Who are you?', parent=root)
label = get_any_child(root, Label)
if answer:
label['text'] = 'You are {}.'.format(answer)
else:
label['text'] = 'I must find out who you are.'
root.after(3000, open_dialog, root)
if __name__ == '__main__':
main()
ted.destroy()it shouldn't close the main window. - Bryan OakleyMainWindowis a window which you think isTextEntryDialog. You addEntrytoMainWindowbecause you didn't use parent inEntry. And you closeMainWindowbut you think you closeTextEntryDialog- furas