analitics

Pages

Monday, April 13, 2026

Python 3.13.0 : bypasses pygame‑ce and use directly to Windows with ctypes.

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)
...

Python 3.13.0 : testing streamlit Python framework for data scientists and AI/ML engineers.

Streamlit is an open-source Python framework for data scientists and AI/ML engineers to deliver interactive data apps – in only a few lines of code.
I run the module streamlit directly, even if Windows cannot find the streamlit command:
python -m pip install streamlit
Collecting streamlit
  Downloading streamlit-1.56.0-py3-none-any.whl.metadata (9.8 kB)
...
Successfully installed altair-6.0.0 gitdb-4.0.12 gitpython-3.1.46 pydeck-0.9.1 smmap-5.0.3 streamlit-1.56.0
Let's test it:
python -m streamlit hello

      Welcome to Streamlit!

      If you'd like to receive helpful onboarding emails, news, offers, promotions,
      and the occasional swag, please enter your email address below. Otherwise,
      leave this field blank.

      Email: ←[0m

  You can find our privacy policy at https://streamlit.io/privacy-policy

  Summary:
  - This open source library collects usage statistics.
  - We cannot see and do not store information contained inside Streamlit apps,
    such as text, charts, images, etc.
  - Telemetry data is stored in servers in the United States.
  - If you'd like to opt out, add the following to %userprofile%/.streamlit/config.toml,
    creating that file if necessary:

    [browser]
    gatherUsageStats = false


  Welcome to Streamlit. Check out our demo in your browser.

  Local URL: http://localhost:8501
  Network URL: http://192.168.1.75:8501

  Ready to create your own Python apps super quickly?
  Head over to https://docs.streamlit.io

  May you create awesome apps!
... and result is this: