Skip to content

Instantly share code, notes, and snippets.

@maaduukaar
Last active July 1, 2025 09:47
Show Gist options
  • Save maaduukaar/0cd0be31a831dc1a11f443aab2250f56 to your computer and use it in GitHub Desktop.
Save maaduukaar/0cd0be31a831dc1a11f443aab2250f56 to your computer and use it in GitHub Desktop.
Get window titles, positions, and sizes on Windows using Python.
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})")
@maaduukaar
Copy link
Author

πŸ“ 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:

pip install pygetwindow

πŸš€ How to run:

  1. Save this code to a file, for example window_info.py.
  2. Run it from the terminal or command prompt:
python window_info.py
  1. Choose the desired window by entering its number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment