Tkinter 主窗口焦点 [英] Tkinter main window focus
问题描述
我有以下代码
window = Tk()
window.lift()
window.attributes("-topmost", True)
这段代码的作用是将我的 Tkinter 窗口显示在所有其他窗口之上,但它仍然只解决了一半的问题.虽然该窗口实际上显示在所有其他窗口之上,但该窗口没有焦点.有没有办法不仅使窗口成为 Tkinter 中最前面的窗口,而且还可以将焦点放在它上面?
This code works in that it displays my Tkinter window above all other windows, but it still only solves half of the problem. While the window is in fact displayed above all other windows, the window does not have focus. Is there a way not only to make the window the frontmost window in Tkinter, but also put focus on it?
推荐答案
如果 focus_force()
不起作用,您可以尝试执行以下操作:
If focus_force()
is not working you can try doing:
window.after(1, lambda: window.focus_force())
本质上是一样的,只是写法不同.我刚刚在 python 2.7 上测试过.
It's essentially the same thing, just written differently. I just tested it on python 2.7.
root.focus_force()
不起作用,但上述方法起作用了.
root.focus_force()
wouldn't work but the above method did.
这篇关于Tkinter 主窗口焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!