Reputation: 894
By placing a Text widget in my GUI
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.
Is there a way of redirecting the focus to another place after writing text?
Upvotes: 0
Views: 2977
Reputation: 241
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()
Upvotes: 2
Reputation: 385940
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.
For example, to set the focus to the root window you would do:
root.focus_set()
Upvotes: 1