Question

I'm looking for a way to make another windows applications window to stay 'on top'.

Example:

You have your program/script that is writing some data into an notepad window for the user to read. That notepad window stays on top of everything else while the user can "browse" around in the background without the notepad window highlighted and will still be able to read from it.

So tkinters wm_attributes("-topmost", 1) wont work since it only affects a window I've created "from scratch". But it should do the same thing only to another window (p.e. notepad).

Was it helpful?

Solution

This solution requires use of the win32gui and win32con modules which are part of the Pywin32 extension.

Providing you already have an instance of the Notepad application running, the following will bring said application to the foreground and keep it there whilst browsing other applications:

import win32gui
import win32con

hwnd = win32gui.FindWindow('Notepad', None)
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 100, 100, 300, 200, 0) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top