Set another program to always be on top?
Asked Answered
K

1

5

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).

Kalakalaazar answered 15/9, 2012 at 17:7 Comment(0)
S
8

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) 
Stanley answered 16/9, 2012 at 14:9 Comment(1)
#40981620Jemmy

© 2022 - 2024 — McMap. All rights reserved.