Python Tkinter entry widget won´t accept input

不羁岁月 提交于 2019-12-11 00:32:06

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/36238110/python-tkinter-entry-widget-won%c2%b4t-accept-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!