Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set another program to always be on top?

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

like image 721
Willy Avatar asked Feb 20 '23 03:02

Willy


1 Answers

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) 
like image 132
Richard Lambert Avatar answered Feb 28 '23 00:02

Richard Lambert