Set another program to always be on top?

∥☆過路亽.° 提交于 2020-05-12 02:56:26

问题


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


回答1:


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) 


来源:https://stackoverflow.com/questions/12439417/set-another-program-to-always-be-on-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!