Tkinter主窗口焦点 [英] Tkinter main window focus

查看:2347
本文介绍了Tkinter主窗口焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码:

window = Tk()
窗口。 lift()
window.attributes( - topmost,True)

因为它显示我的Tkinter窗口高于所有其他窗口,但它仍然只解决了一半的问题。实际上,窗口显示在所有其他窗口的上方,窗口没有焦点。有没有办法使窗口在Tkinter的最前面的窗口,但也把重点放在它? 解决方案

code> focus_force()不工作,你可以试试:


$ b

  

它本质上是一样的,只是写法不同而已。我只是测试它在python 2.7。
$ b

root.focus_force()不会工作,但上述方法。


I have the following code

window = Tk()
window.lift()
window.attributes("-topmost", True)

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?

解决方案

If focus_force() is not working you can try doing:

window.after(1, lambda: window.focus_force())

It's essentially the same thing, just written differently. I just tested it on python 2.7.

root.focus_force() wouldn't work but the above method did.

这篇关于Tkinter主窗口焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆