Tkinter key-binds not working after message box Tkinter key-binds not working after message box tkinter tkinter

Tkinter key-binds not working after message box


Tkinters messagebox needs to be imported separately:

from tkinter import messagebox

Then add the following underneath the line for your bindings messagebox:

master.focus_force()

This will move the focus back to the root window after the user closes the messagebox and all your bindings will continue to work.


I'm posting here for I don't have privilege to comment yet.. @R Oliver, I had a similar problem with my entry widget.. The following solution, provided by Brian Oakley as a comment in this question, worked for me, using after_idle() and having the message as a function. Try this:create some function for the info

def message():    messagebox.showinfo("Guide", "Key bindings include: 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, ., +, -, *, /, (, ), Enter, Backspace, Insert and Delete.")

and then, in main, use the after_idle

if __name__ == '__main__':    root = Tk()    calculator = GUI(root)    root.after_idle(message)    root.mainloop()