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