Today, I test bypasses pygame‑ce and use directly to Windows, because the Python 3.13 + pygame‑ce 2.5.7, where DPI functions are missing.
You can read more about this idea on my pygame blogger, see the blogger post.
Windows exposes thousands of functions through: user32.dll, gdi32.dll, shcore.dll, kernel32.dll, dwmapi.dll.
If the OS provides the feature → Python can call it via ctypes.
Python can call Windows API functions directly whenever the OS provides a stable API, and you only perform operations that are safe at the OS level.
These are always safe to do from Python using ctypes, because they only interact with the OS, not with internal memory of another library.
- Reading information
- DPI
- monitor list
- window position
- window size
- screen resolution
- system metrics
- OS version
- keyboard/mouse state
- window styles
- process info
- Calling OS-level functions that modify the window
- move window
- resize window
- change window title
- change window transparency
- change window z-order
- set DPI awareness
- toggle fullscreen
- minimize / maximize
- Creating new OS objects
- timers
- threads
- windows (if you want)
- file handles
- pipes
- events
- Using OS-level graphics
- GDI drawing
- DWM effects
- Aero shadow
- blur behind window
- Unsafe
- Writing into internal memory of SDL2, Python, or any DLL
- Overwriting function pointers
- Injecting hooks
- Modifying struct layouts
- Freeing memory you don’t own
This is just one part of source code:
import pygame
import pygame._sdl2 as sdl2
import ctypes
import sys
pygame.init()
# Windows DPI API
user32 = ctypes.windll.user32
shcore = ctypes.windll.shcore
# Enable per-monitor DPI awareness
try:
shcore.SetProcessDpiAwareness(2)
except:
pass
...
user32.EnumDisplayMonitors(0, 0, MonitorEnumProc(_monitor_enum_proc), 0)
...