import sys from functools import cmp_to_key import pygetwindow as gw import ctypes from win32api import GetMonitorInfo, MonitorFromPoint primary_monitor = MonitorFromPoint((0, 0)) monitor_info = GetMonitorInfo(primary_monitor) monitor_area = monitor_info.get("Monitor") work_area = monitor_info.get("Work") work_height = work_area[3] taskbar_height = monitor_area[3] - work_area[3] 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", "Host für die Windows Shell-Oberfläche", ]: 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), work_height)