How can I get and set the window (any windows program) position and size with python?
1] Use Shift key while closing a window However, you need to click on that same button when holding the Shift key on your keyboard. This trick helps Windows OS to remember the window position.
You can get the window coordinates using the GetWindowRect function. For this, you need a handle to the window, which you can get using FindWindow , assuming you know something about the window (such as its title). To call Win32 API functions from Python, use pywin32 .
Right-click the window tab and select Move>View (to move a separate window). Move the mouse to where you want the window to display and left-click to confirm the move.
Assuming you're on Windows, try using pywin32
's win32gui
module with its EnumWindows
and GetWindowRect
functions.
If you're using Mac OS X, you could try using appscript
.
For Linux, you can try one of the many interfaces to X11.
Edit: Example for Windows (not tested):
import win32gui def callback(hwnd, extra): rect = win32gui.GetWindowRect(hwnd) x = rect[0] y = rect[1] w = rect[2] - x h = rect[3] - y print("Window %s:" % win32gui.GetWindowText(hwnd)) print("\tLocation: (%d, %d)" % (x, y)) print("\t Size: (%d, %d)" % (w, h)) def main(): win32gui.EnumWindows(callback, None) if __name__ == '__main__': main()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With