2

Here is some simplified code. Let's just say that, for reasons not relevant to this example, I want to make the root window active, not just on top.

from tkinter import *
import time

root = Tk()


def wake():
    time.sleep(3)
    root.attributes("-topmost", True)
    root.attributes("-topmost", FALSE)

button = Button(root, text='Bring Forth!', command=wake)
button.pack()

root.mainloop()

When you press the button and go to another application, it reappears on top, but not "active", like the "tk" title and menu buttons are gray until you click somewhere on the GUI. I know it seems weird, but it would be very helpful. Thank you

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
MANA624
  • 986
  • 4
  • 10
  • 34
  • Which platform are you talking about? Windows? MacOS X? Something else? Tkinter apps seem to have a hard time activating with MacOS X, so people use workarounds like this: http://stackoverflow.com/a/32121848/39223 – RJHunter Dec 15 '15 at 08:05
  • Have you tried `w.focus_force()`. Check [here](http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/universal.html). – Quirk Dec 15 '15 at 08:06
  • I'm running a Windows platform. I tried root.focus_force(), but it didn't seem to do anything, though the description seemed to match what I was trying to do. I also tried root.grab_set_global further down the list, but with no luck :( – MANA624 Dec 15 '15 at 18:06
  • Interestingly, when I call grab_set in OS X, the icon bounces up and down. I assume this does something on Windows? – Jonah Fleming Dec 15 '15 at 21:21
  • I'm not terribly familiar with OS X. Do you mean the icon in the top left? Because it doesn't appear to do anything on Windows. – MANA624 Dec 15 '15 at 23:02
  • No. There is a dock at the bottom of the screen with app icons and it bounces on that. – Jonah Fleming Dec 16 '15 at 05:53

1 Answers1

0

Try calling root.grab_set() then root.focus() like this:

def wake():
    time.sleep(3)
    root.attributes("-topmost", True)
    root.grab_set()
    root.focus()
    root.attributes("-topmost", FALSE)

It works on windows 7 Professional..

Jonah Fleming
  • 1,187
  • 4
  • 19
  • 31