Tkinter TkMessageBox not closing after click OK Tkinter TkMessageBox not closing after click OK tkinter tkinter

Tkinter TkMessageBox not closing after click OK


Try calling root.update() before returning from the function. That will process all pending Tk/X window events.

(ideally, you'd establish a main event loop before displaying the window, but that assumes that your entire program is event driven, which may not always work.)


You have to call root.mainloop() to enable the program to respond to events.


One problem on your code is that you create a new Tk element each time you call the function window_warn. This might not be the cause of your issue, but creating multiple Tk elements is a bad practise that should be avoided. For instance, initialize the root element at the beginning and leave only the call to showwarning:

root = Tkinter.Tk()root.withdraw()def window_warn():    '''This function will throw up a window with some text'''    tkMessageBox.showwarning("New Case", "You have a new case\n Please restart pycheck")    returnprint "Just started newcase check"while True:    # ...