Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Are you talking about activating a window that you created in wx or a separate application, like notepad? If it's with wx, then it's trivial. You'd just use Raise() to bring whatever frame you need into focus. You would probably use PubSub or PostEvent to let the sub-frame know that it needs to Raise.</p> <p>If you're talking about notepad, then things get much stickier. Here's an ugly hack I created based on some stuff I got from various locations on the web and the PyWin32 mailing list:</p> <pre><code>def windowEnumerationHandler(self, hwnd, resultList): ''' This is a handler to be passed to win32gui.EnumWindows() to generate a list of (window handle, window text) tuples. ''' resultList.append((hwnd, win32gui.GetWindowText(hwnd))) def bringToFront(self, windowText): ''' Method to look for an open window that has a title that matches the passed in text. If found, it will proceed to attempt to make that window the Foreground Window. ''' secondsPassed = 0 while secondsPassed &lt;= 5: # sleep one second to give the window time to appear wx.Sleep(1) print 'bringing to front' topWindows = [] # pass in an empty list to be filled # somehow this call returns the list with the same variable name win32gui.EnumWindows(self.windowEnumerationHandler, topWindows) print len(topWindows) # loop through windows and find the one we want for i in topWindows: if windowText in i[1]: print i[1] win32gui.ShowWindow(i[0],5) win32gui.SetForegroundWindow(i[0]) # loop for 5-10 seconds, then break or raise handle = win32gui.GetForegroundWindow() if windowText in win32gui.GetWindowText(handle): break else: # increment counter and loop again secondsPassed += 1 </code></pre> <p>Then I used the SendKeys package to send text to the window (see <a href="http://www.rutherfurd.net/python/sendkeys/" rel="nofollow">http://www.rutherfurd.net/python/sendkeys/</a>). If the user opens anything else, the script will break or weird things will happen. If you open something like MS Office, use win32com instead of SendKeys. That's much more reliable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload