简体   繁体   English

如何使用 python 打开最小化的 window?

[英]How do I open a minimized window using python?

is it possible to un-minimize a minimized window using python on windows 10?是否可以在 windows 10 上使用 python 来取消最小化 window? (I'm using python 3.8) (我正在使用 python 3.8)

I would add more detail but that's really all I need to say.我会添加更多细节,但这就是我需要说的。

I combined information from multiple sources and got this to work (Miniconda Python 3.6, Windows 10)我结合了来自多个来源的信息并使其工作(Miniconda Python 3.6,Windows 10)

import win32gui
import win32con

def windowEnumHandler(hwnd, top_windows):
    top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))

def bringToFront(window_name):
    top_windows = []
    win32gui.EnumWindows(windowEnumHandler, top_windows)
    for i in top_windows:
        # print(i[1])
        if window_name.lower() in i[1].lower():
            # print("found", window_name)
            win32gui.ShowWindow(i[0], win32con.SW_SHOWNORMAL)
            win32gui.SetForegroundWindow(i[0])
            break

# Test with notepad
if __name__ == "__main__":
    winname = "notepad"
    bringToFront(winname)

The Handler is not optimal; Handler 不是最优的; it spits out various processes that are not the windows in the taskbar.它会在任务栏中吐出不是 windows 的各种进程。 However, as long as your window_name is specific I don't think you'll run into problems.但是,只要您的window_name是特定的,我认为您不会遇到问题。 If you remove the break , all matches will be "opened".如果删除break ,所有匹配项都将“打开”。

Sources: Mouse and Python Blog资料来源: 鼠标和 Python 博客

Another StackOverflow question 另一个 StackOverflow 问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 selenium python 中最小化打开浏览器 window? - How to open browser window as minimized in selenium python? 如何检查 tkinter window 是否被最小化? - How do I check if a tkinter window is minimized? 如何使用wxPython检测窗口何时最小化? - How do I detect when my window is minimized with wxPython? 如何提升最小化或被 PyGObject 覆盖的窗口? - How do I raise a window that is minimized or covered with PyGObject? 我将如何制作一个无法在 Python Tkinter 中最小化的 tk 窗口? - How will I make a tk window which cannot be minimized in Python Tkinter? 如何在wxpython / python中恢复最小化的窗口/框架 - How to restore a minimized Window/Frame in wxpython/python 如何知道 Window 是否通过 python ctypes 最小化? - How to know if the Window is minimized via python ctypes? 使用 Python,如何检测程序是最小化还是最大化? - Using Python, how can I detect whether a program is minimized or maximized? 如何在 WINdows 10 中打开 Python IDLE (Shell WIndow)? - How do I open Python IDLE (Shell WIndow) in WIndows 10? 在python中,如何通过使用从QtDesigner中创建的.ui文件创建的.py文件单击主窗口中的按钮来打开新窗口? - In python, how do I open a new window by clicking a button in a main window using .py files created from .ui files made in QtDesigner?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM