Skip to content Skip to sidebar Skip to footer

Open Window And Focus Textbox Tkinter

I have a (second) tkinter window, which, when opened, does not get the focus, but rather the first window remains focused (although the second window appears in front of the other)

Solution 1:

It turns out that you can simply call the secondary window's deiconify() method and then the widget's focus_set() method:

toplevel.deiconify()
text.focus_set()

Here's the original work-around for Windows (no longer recommended):

Start by adding import ctypes at the top. Go ahead and focus your widget like you have with: text.focus_set() Get the hwnd of the second window: top_hwnd = toplevel.winfo_id() And finally activate the second window with: ctypes.windll.user32.SetFocus(top_hwnd)

Post a Comment for "Open Window And Focus Textbox Tkinter"