Skip to main content

Add utility methods that allow you to easily grab the position of a window

Project description

A tiny Python utility library used to get the bounds of an application window.

The get_window_pos function takes either a string, or a callable where the first argument is a string and that returns a boolean.

As an example, we'll get the position of Discord. As Discord's window title can vary depending on what server and channel you're in, we'll take advantage of the expected callable and pass a lambda to see if the window ends with 'Discord'.

from WinPos import get_window_pos

get_window_pos(lambda title: title.endswith('Discord'))
# (619, 473, 1624, 716)

Not all windows are as complicated as Discord, fortunately. If the window you're trying to get the position of is static and never changes, you can simply pass a string through and get your value.

from WinPos import get_window_pos

get_window_pos('Task Manager')
# (125, 117, 895, 726)

If for whatever reason you need to repeatedly get the position of the same window, you can import get_window_hwnd and get_window_pos_from_hwnd functions. This will save some time from not having to iterate over every application to check the title.

from WinPos import get_window_hwnd, get_window_pos_from_hwnd

hwnd = get_window_hwnd('Task Manager')
get_window_pos_from_hwnd(hwnd)
# (125, 117, 895, 726)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

win-pos-0.1.0.tar.gz (2.8 kB view hashes)

Uploaded Source

Built Distribution

win_pos-0.1.0-py3-none-any.whl (2.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page