I have the following code
window = Tk()
window.lift()
window.attributes(\"-topmost\", True)
This co
Note: this is Windows specific. This focuses the whole main window. Essentially forcing an alt-tab to reach the window.
None of these answers worked for me, the tk window would appear on top of everything with the -topmost flag, my input box would have focus, but the window itself wouldn't, which meant that typing wouldn't appear in the tk window. It looks like like this:
What helped was adding a call to the Windows API to steal focus:
import win32gui
root = tk.Tk()
# Application specific setup ...
win32gui.SetForegroundWindow(root.winfo_id())
Disclaimer: Stealing focus is bad behaviour, so only use it if you must and if it makes sense, e.g. input box the user will instantly type into.