B
B
breadp2018-05-15 21:10:17
Python
breadp, 2018-05-15 21:10:17

How to bring a windows window to the front?

There is a script in which you need to bring the telegram window to the foreground, I actively used pyautogui, but I didn’t find such a function there, I couldn’t figure it out with pywinauto, maybe someone here will advise how to implement it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2018-05-15
@NeiroNx

You need to install Pywin32 (win32api)
FindWindow
SetForegroundWindow
ShowWindow

hwnd = win32gui.FindWindow(None,"Telegram")
win32gui.ShowWindow(hwnd, win32con.SW_NORMAL)
win32gui.SetForegroundWindow(hwnd)

V
Vasily Ryabov, 2018-05-18
@vasily-v-ryabov

Or with pywinauto:

from pywinauto.application import Application

app = Application().connect(title_re="Telegram")
app.window(title_re='Telegram \(\d+\)').set_focus()

In general, I see that the entire Telegram client is made on some custom elements based on Qt5. Not a single normal name is visible in Inspect.exe. One pictures. And yet the window does not move anywhere from the center - is it a bug or so brilliantly conceived?

E
Ermac301, 2021-08-26
@Ermac301

But what if I need, for example, just bring to the "Foreground" a window with a name such as "notepad" in windows 10, if it's not difficult, please write the whole code and not a cut from the code (as Alexander wrote in the first answer), if it's even possible on Python language (What is obvious to professionals is not obvious to beginners, and professionals will not look for answers to such questions)
This code does not expand the Notepad window in any way, what am I doing wrong?

import win32gui
import FindWindow
import SetForegroundWindow
import ShowWindow
hwnd = win32gui.FindWindow(None,"notepad")
win32gui.ShowWindow(hwnd, win32con.SW_NORMAL)
win32gui.SetForegroundWindow(hwnd)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question