Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Tkinter entry widget won´t accept input

I have run into a very weird Problem with Tkinter entry widgets. When I try to enter something into them they don´t accept my input.

After some PC restarting and Python reinstalling I figured out why this happens: I had a messagebox just before the root.mainloop() in the code. The code looks something like this:

def xyz():
    if not messagebox.askyesno("Title","Some text"):
        exit()
xyz()
root.mainloop()

I found, to resolve the issue you can just manually focus on a different window and then back again. I would like to know if there is some better way to do this? I would like to keep my messagebox, AND dont´t want the unelegant solution of manually changing window focus.

like image 629
Sebastian Hietsch Avatar asked Jul 30 '26 03:07

Sebastian Hietsch


1 Answers

You can fix the code like this:

def xyz():
    if not messagebox.askyesno("Title","Some text"):
        exit()
root.after(10,xyz) #show the messagebox after root.mainloop()
root.mainloop()
like image 100
Leo Leontev Avatar answered Aug 01 '26 18:08

Leo Leontev