[英]How to remove focus out of a Text widget in Tkinter, Python
By placing a Text widget in my GUI通过在我的 GUI 中放置一个 Text 小部件
from Tkinter import Text
textBox=Text(root, height=20, width=10)
textBox.pack()
whenever I write something in that box, I cant return the focus back to any other place in the window.每当我在那个框中写东西时,我都无法将焦点返回到窗口中的任何其他位置。 I have some keys bounded to event, which stop working after I wrote in the Text widget.
我有一些绑定到事件的键,在我在 Text 小部件中写入后停止工作。
Is there a way of redirecting the focus to another place after writing text?有没有办法在写完文本后将焦点重定向到另一个地方?
Please press Return-Key to give focus back to window请按回车键将焦点返回到窗口
import tkinter as tk
def onReturn(*event):
root.focus_set()
root = tk.Tk()
textBox= tk.Text(root, height=20, width=10)
textBox.pack()
root.bind("<Return>", onReturn)
root.mainloop()
Is there a way of redirecting the focus to another place after writing text?
有没有办法在写完文本后将焦点重定向到另一个地方?
Every widget has a method named focus_set
which can be used to move keyboard focus to that widget.每个小部件都有一个名为
focus_set
的方法,可用于将键盘焦点移动到该小部件。
For example, to set the focus to the root window you would do:例如,要将焦点设置到根窗口,您可以执行以下操作:
root.focus_set()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.