Last active
July 1, 2025 09:47
-
-
Save maaduukaar/0cd0be31a831dc1a11f443aab2250f56 to your computer and use it in GitHub Desktop.
Get window titles, positions, and sizes on Windows using Python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygetwindow as gw | |
# Get a list of all windows with non-empty titles | |
windows = [w for w in gw.getAllWindows() if w.title.strip() != ''] | |
# Check if there are any available windows | |
if not windows: | |
print("No windows with non-empty titles were found.") | |
exit() | |
# Display the list of available windows with index numbers | |
print("List of available windows:") | |
for i, window in enumerate(windows): | |
print(f"{i}: {window.title}") | |
# Ask the user to select a window by its number | |
while True: | |
try: | |
selection = int(input("\nEnter the window number: ")) | |
if 0 <= selection < len(windows): | |
break | |
else: | |
print("Please enter a valid number from the list.") | |
except ValueError: | |
print("Please enter an integer number.") | |
# Get the selected window | |
window = windows[selection] | |
# Display the window information | |
print("\nSelected window information:") | |
print(f"Title: {window.title}") | |
print(f"Position: (X: {window.left}, Y: {window.top})") | |
print(f"Size: (Width: {window.width}, Height: {window.height})") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
π Description:
A simple Python script that lists all currently open windows with visible titles on your desktop. It allows you to select a window by its index and displays its title, screen position (X, Y), and size (width and height). Useful for automation, UI debugging, and window management tasks.
π§ Install the required library:
π How to run:
window_info.py
.