[Python] How to rename and keep the window name fixed without updating when refreshing...

Discussão em 'Python' iniciado por Stack, Agosto 12, 2025.

  1. Stack

    Stack Membro Participativo

    My current code opens the desired URL and rename the window to the string I prefer, but just update the page that is open to the browser and with that my personalized name is lost and the web page title is again:

    import pygetwindow as gw
    import subprocess
    import ctypes
    import time

    def open_and_rename(url: str, new_title: str):
    windows_before = set(gw.getAllTitles())

    subprocess.Popen([r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", '--new-window', url])
    time.sleep(1)

    windows_after = set(gw.getAllTitles())
    new_windows = windows_after - windows_before

    if new_windows:
    new_window_title = list(new_windows)[0]
    window = gw.getWindowsWithTitle(new_window_title)[0]
    hwnd = window._hWnd
    ctypes.windll.user32.SetWindowTextW(hwnd, new_title)
    else:
    print("new window not found")

    open_and_rename("https://www.google.com/", "Test")


    But my desire is that it works exactly like this function of browsers Chrome and Edge:

    [​IMG]

    With this option you rename the window and this value becomes fixed regardless of what you do in the browser (this option you find by clicking with the right side of the mouse both in the top of the window and the same action on the window miniature leaving the mouse on it in the taskbar)

    Is there a way to do this on Python + Windows 11 without using Python moving simulators and mouse clicks and keyboard typing?

    Continue reading...

Compartilhe esta Página