How can I guarantee that application windows are always on top?

I have a simple Python script that runs in console windows.

How can I make sure the console window is always on top and, if possible, resize it?

+3
source share
3 answers

To do this using the cmd window, you will probably have to make many win32 calls.

  • List all windows using win32gui.EnumWindows to get window handles.
  • " ", , . , .py "C:\Python26\python.exe". , c:\Windows\system32\cmd.exe - c:\python26\python.exe test.py
  • , cmd.
  • win32gui.SetWindowPos, " " ..

mport win32gui, win32process, win32con
import os

windowList = []
win32gui.EnumWindows(lambda hwnd, windowList: windowList.append((win32gui.GetWindowText(hwnd),hwnd)), windowList)
cmdWindow = [i for i in windowList if "c:\python26\python.exe" in i[0].lower()]
win32gui.SetWindowPos(cmdWindow[0][1],win32con.HWND_TOPMOST,0,0,100,100,0) #100,100 is the size of the window
+1

:

import win32gui
import win32con

hwnd = win32gui.GetForegroundWindow()
win32gui.SetWindowPos(hwnd,win32con.HWND_TOPMOST,100,100,200,200,0)
+5

, Tkinter " ":

from Tkinter import *
root = Tk()
root.wm_attributes("-topmost", 1)
root.mainloop()

, , .

, Windows, . script Autohotkey.

+1
source

Source: https://habr.com/ru/post/1764038/


All Articles