简体   繁体   中英

How to resize active window through Python

I want to write a python script that will increase the width of the Windows window that's currently active (whether that's cmd.exe, or an IDE, just whatever Window is active). How could we achieve that?

You can use the "win32gui" lib to get the current window and then resize it. Here's how -

import win32gui
current = win32gui.GetForegroundWindow()
win32gui.MoveWindow(current, 0, 0, 1000, 700, True)

This will "get" the current window, move it to specified position (0,0) and then resize it to the specified value (1000,700).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM