Search code examples
pythontkintermessagebox

Tkinter main window becomes unresponsive after message box


I have problem with Tkinter. After messagebox I can't edit Entry in main window. Below simply code with this problem. Can you help me?

from tkinter import messagebox, Entry, Tk


def pop_error():
    messagebox.showerror(message="Error")


win = Tk()
entry = Entry(win)
entry.grid()
pop_error()
win.mainloop()

Solution

  • Force the Entry to focus after closing the messagebox

    from tkinter import messagebox, Entry, Tk
    
    def pop_error():
        messagebox.showerror(message="Error")
    
    win = Tk()
    entry = Entry(win)
    entry.grid()
    pop_error()
    entry.focus_force()
    win.mainloop()