I am trying to make a Toplevel
widget that is the active window on the screen (I want it so that if you press Enter, it exits the window. I already h
I tried the above solutions and found that focus_force()
alone worked on Windows Vista/Python 3.3. Also it may help to include the takefocus=True
method while creating your Toplevel window.
I had the same problem and tried everything I could find. Unfortunately, the answer is that it depends on your OS. My window is automatically focused on my old Mac, but not on OSX Lion. Some of the commands you list are OS-dependant, too.
...however, I have to click in the window first so that it becomes active, and then it works.
I just encountered this problem and while I was researching a solution, I found this thread. I'm using Windows 7 Professional. All I did was call both grab_set()
and focus()
and it solved the problem for me. You already have finalRoot.grab_set()
, just add:
finalRoot.focus()
It worked in my case.
root.call('wm', 'attributes', '.', '-topmost', True)
root.after_idle(root.call, 'wm', 'attributes', '.', '-topmost', False)
root.focus_force()
Here is the code which worked for me
root= tk.Tk()
root.title("Main Window")
top = tk.Toplevel()
top.title("Topelevel Window")
top.grab_set() #for disable main window
top.attributes('-topmost',True) #for focus on toplevel
root.mainloop()
None of the above suggestions worked for me on Mac OS El Capitan, but this does:
class Window(Tk.Toplevel):
...
def setActive(self):
self.lift()
self.focus_force()
self.grab_set()
self.grab_release()
...