Question

Consider the following MWE:

from Tkinter import *
root = Tk()
Label(root,text="foo").pack()
root.mainloop()

I want to set a newly created Tkinter window that does not include any "focusable" controls like buttons to the foreground. If I run the code above (from a shell), the window is inactive and therefore not able to react to key bindings.

Is there any way to bring such a window to the foreground?

[Edit] I am using Python 2.7.5 and OS X Mavericks. I run the code from a terminal window and the focus stays at that window even though the Tkinter window is created properly.

Was it helpful?

Solution

Just tried it on IDLE:

>>> from Tkinter import *
>>> root=Tk()
>>> root.focus_force()
>>> Label(root,text="foo").pack()
>>> root.mainloop()

Worked like a charm!(Edit: on Windows apparently!)

Edit:This is a standard behavior

OTHER TIPS

Maybe you're doing something wrong, because below works perfectly for me: could be platform issue ??

from Tkinter import *
root = Tk()
Label(root,text="foo").pack()

root.geometry("%dx%d+%d+%d" % (200,100,0,0))
#made it a bigger window to see better...
root.wm_attributes("-topmost", 1)
root.focus_force()

root.mainloop()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top