Sebastian Hietsch
Sebastian Hietsch

Reputation: 474

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.

Upvotes: 3

Views: 1083

Answers (1)

Lev Leontev
Lev Leontev

Reputation: 2615

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()

Upvotes: 1

Related Questions