Question

I am playing around with the example from here; esp. I have this code:

from osax import *

sa = OSAX()

print sa.display_dialog("Python says hello!",
                        buttons=["Hi!", "Howdy!", "Duuuude!"],
                        default_button=3)

The dialog always opens in the background. How can I open it in (or move it to) the foreground?

Était-ce utile?

La solution

Add an activate command to give your Python process the window manager application focus.

sa = OSAX()
sa.activate()
print sa.display_dialog(...)

You can also choose to not GUIfy your Python process by targeting a faceless background app as described here.

Autres conseils

This works for now:

def go_foreground():
    from AppKit import NSApp, NSApplication
    NSApplication.sharedApplication()
    NSApp().activateIgnoringOtherApps_(True)
go_foreground()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top