import sys import pygetwindow as gw from functools import cmp_to_key import ctypes user32 = ctypes.windll.user32 screen_width = user32.GetSystemMetrics(0) screen_height = user32.GetSystemMetrics(1) # Get all windows windows = gw.getAllWindows() active_windows = [] for window in windows: if window.isMinimized: continue if window.topleft.x < 0: continue if window.title == "": continue if window.title in [ "Program Manager", "Microsoft Text Input Application", "Einstellungen" ]: continue print(window.title) active_windows.append(window) active_windows.sort( key = cmp_to_key( lambda item1, item2: item1.topleft.x - item2.topleft.x)) nr_of_windows = len( active_windows ) width = float(screen_width / nr_of_windows) for index in range( nr_of_windows ): window = active_windows[ index ] window.moveTo( int(index * width), 0) window.resizeTo( int(width), screen_height)